Page 1 of 1

Scan for ip

Posted: Sat Jun 19, 2004 9:52 pm
by Rookie
How would you go about scanning each ip address to see if anotrher network server was open by the same program

Posted: Sat Jun 19, 2004 11:20 pm
by Johan_Haegg
Well, you will have to go through a lot of problem with WinPCAP if you just want to listen to all data transmitted over the network and then check for something specific for that program. You could just try to connect to every host on a port.
Here is an probably old and buggy version of a network scanner i wrote a while ago

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


Posted: Mon Jun 21, 2004 5:17 pm
by Rookie
ConsoleTitle(#VersionTitle + " Build: " + Str(#jaPBe_ExecuteBuild) + " Scanning Port: " + Str(Offset + MaxThreads))

This line right is giving me an error about constat not found can you help out

Posted: Mon Jun 21, 2004 5:19 pm
by fweil
Just remove or change this by a constant string that exist.

This is just you are not using JAPBe. Nothing critical about the program's execution.

Rgrds

Posted: Thu Jun 24, 2004 5:57 pm
by Rookie
What would i make the constat into

Posted: Thu Jun 24, 2004 6:00 pm
by fweil
ie replace :

ConsoleTitle(#VersionTitle + " Build: " + Str(#jaPBe_ExecuteBuild) + " Scanning Port: " + Str(Offset + MaxThreads))

by

ConsoleTitle(#VersionTitle + " Build: " + Str(0) + " Scanning Port: " + Str(Offset + MaxThreads))