Jump to content
Sign in to follow this  
typewriter

timeout problem tpc TCPConnect

Recommended Posts

Hallo Guys,

First of all appologies for my English.

I've got the following problem.

In my local network i wan't to scan all devices, wich include pc's but also printers, en discover some services.

First I ping all ip adresses i'm intersted in. Then if i get a reply I try to discover the running services, life e.g. FTP

So I try to connect to port 21. If available, the pc wich is running an ftp server responds quickley. But there are pc's wich do not

run an ftp server, so I have to wait until an timeout occurs. And this takes more time then I would like. I've tried with tcptimeout, but that does not seems to work with tcpconnect.

I would think that adlib could be of some use, but i just can't seem to get it to work.

My code

#include <GUIConstants.au3>
#include <string.au3>
Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("mega Ping", 800, 300)
$okbutton = GUICtrlCreateButton("OK", 10, 270, 60)

$inputRange=GUICtrlCreateInput ("", 10,  10, 80, 20) 
$inputStart=GUICtrlCreateInput ("", 100,  10, 60, 20) 
$inputEnd=GUICtrlCreateInput ("", 180,  10, 60, 20)

$listviewfree = GUICtrlCreateListView ("vrij                     ",40,40,100,150);
$listviewnotfree = GUICtrlCreateListView ("bezet                |netbios          |ftp / vnc / web ",340,40,400,150);

GUICtrlSetOnEvent($okbutton, "OKButton")
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
While 1
  Sleep(1000) 
WEnd


Func netbiosnaam($y, ByRef $x)
    UDPStartup()
    $socket=udpopen($y,137)
    UDPSend($socket,_HexToString("8E1A0000000100000000000020434B414141414141414141414141414141414141414141414141414141414141000021

0001"))
    $data=UDPRecv($socket,289)
    $x=StringMid($data,58,15)
EndFunc

Func identify($y,ByRef $z)
    TCPStartup()
    $socket = TCPConnect( $y, 21 )
    If $socket = -1 Then 
        MsgBox (0,"","no")
    else 
        MsgBox (0,"","yes")
    EndIf   
EndFunc


Func OKButton()
     $start=GUICtrlRead($inputStart)
     $range=GUICtrlRead($inputRange)
     $end=GUICtrlRead($inputEnd)
     While $start <= $end
          $y=$range&"."&$start
          $var = Ping($y,150)
          If $var Then
                $x=""
                $z=""
                netbiosnaam($y,$x)
                identify($y,$z)
                GUICtrlCreateListViewItem ( $y&"|"&$x&"|"&$z, $listviewnotfree)
            else
                GUICtrlCreateListViewItem ( $y, $listviewfree)
          EndIf
     $start = $start + 1
     WEnd
EndFunc

Func CLOSEClicked()
  Exit
EndFunc

Share this post


Link to post
Share on other sites
It's a great utility, but I would like to use the socket functionality in autoit, rather then use an external program. Otherwise I could use the ported version of Netcat. But thanks for taking the time for looking at my problem. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...