Scan for ip

Just starting out? Need help? Post your questions and find answers here.
Rookie
Enthusiast
Enthusiast
Posts: 106
Joined: Tue May 20, 2003 4:16 pm
Location: Florida
Contact:

Scan for ip

Post by Rookie »

How would you go about scanning each ip address to see if anotrher network server was open by the same program
Insanity is over rated, unless you can join me in mine.
Don't post questions at work
Don't post questions at work
Don't post questions at work
Johan_Haegg
User
User
Posts: 60
Joined: Wed Apr 30, 2003 2:25 pm
Location: Västerås
Contact:

Post 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

Rookie
Enthusiast
Enthusiast
Posts: 106
Joined: Tue May 20, 2003 4:16 pm
Location: Florida
Contact:

Post 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
Insanity is over rated, unless you can join me in mine.
Don't post questions at work
Don't post questions at work
Don't post questions at work
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Rookie
Enthusiast
Enthusiast
Posts: 106
Joined: Tue May 20, 2003 4:16 pm
Location: Florida
Contact:

Post by Rookie »

What would i make the constat into
Insanity is over rated, unless you can join me in mine.
Don't post questions at work
Don't post questions at work
Don't post questions at work
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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))
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Post Reply