Scan for ip
Posted: Sat Jun 19, 2004 9:52 pm
How would you go about scanning each ip address to see if anotrher network server was open by the same program
Code: Select all
#VersionTitle = "PortScan 0.0.2"
OpenConsole()
Global IP.s
Global MaxThreads.l
Global ThreadQuit.b
IP.s = ProgramParameter()
;IP.s = "127.0.0.1"
MaxThreads.l = Val(ProgramParameter())
If MaxThreads.l = 0
MaxThreads.l = 256
EndIf
If IP.s = ""
PrintN("portscan IP [maxthreads]")
End
EndIf
NewList OpenPorts.l()
InitNetwork()
Global Items.w
Global Procs.w
Global IP.s
Procedure Probe(Port.w)
Protected ConID.l
ConID = OpenNetworkConnection(IP.s, Port.w)
If ConID
PrintN(Str(Port.w))
AddElement(OpenPorts())
OpenPorts() = Port.w
Items.w + 1
CloseNetworkConnection(ConID)
EndIf
Procs.w - 1
EndProcedure
Procedure Sniffit(Port.w)
Protected ConID.l
Protected DatString.s
ConID = OpenNetworkConnection(IP.s, Port.w)
If ConID
PrintN("Connected to " + Str(Port.w))
Protected Char.b
Repeat
If NetworkClientEvent(ConID) = 2
ReceiveNetworkData(ConID, @Char, 1)
DatString.s + Str(Char)
If Char = 13 Or Len(DatString.s) = 80
Print(Str(Port.w) + ": " + DatString.s)
DatString.s = ""
EndIf
EndIf
Delay(100)
Until ThreadQuit = 1
Print(Str(Port.w) + ": " + DatString.s)
EndIf
EndProcedure
;- Prototypes
Declare ListToArray()
;- Main Code
Repeat
Procs = MaxThreads
For a = 1 To MaxThreads
CreateThread(@Probe(), Offset + a)
Delay(1)
Next
ConsoleTitle(#VersionTitle + " Build: " + Str(#jaPBe_ExecuteBuild) + " Scanning Port: " + Str(Offset + MaxThreads))
Repeat
If Procs = 0
Break
EndIf
If UCase(Left(Inkey(),1)) = "Q"
Quit = 1
Break
EndIf
Delay(20)
ForEver
Offset + MaxThreads
Until Quit = 1
PrintN("Starting to sniff in 3sec")
Delay(3000)
Dim PortArray.w(Items.w)
ListToArray()
For a = 1 To Items.w
CreateThread(@Sniffit(), PortArray.w(a))
Delay(1)
Next
Repeat
If Left(Inkey(),1) = "Q"
ThreadQuit = 1
EndIf
Delay(50)
Until ThreadQuit = 1
PrintN("Waiting 3sec for threads to close")
Delay(3000)
;- Procedures
Procedure ListToArray()
AddElement(OpenPorts())
FirstElement(OpenPorts())
For a = 1 To Items.w
PortArray(a) = OpenPorts()
NextElement(OpenPorts())
Next
SortArray(PortArray(), 0)
EndProcedure