Jump to content
Sign in to follow this  
enaiman

how to detect if a TFTP application is running?

Recommended Posts

enaiman

I wonder if it is possible to detect if a TFTP server application is running or not. (the application name is unknown = it could be any TFTP type application so ProcessList won't help)

I know that a TFTP server listens on port 69 but I'm not sure if it opens that port or not (I suppose "listening" = opening the port but I might be wrong about).

What I tried so far:

I made a small script to open UDP port 69

UDPStartup()
$socket = UDPOpen("192.168.0.30", 69)
If @error Then 
    MsgBox(16,"err", "can't open")
Else
    MsgBox(16,"ok", "opened")
EndIf
UDPCloseSocket($socket)
UDPShutdown()

Ran this with a TFTP server running and without (hoping that if the server is running I won't be able to open the port) and the result: I always opened the port no matter the status of TFTP server.

Can some1 give me some ideas about how could I detect if something is listening on this port?

Thank you,

edit: Tried also 127.0.0.1 for IP and got the same result

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
CoePSX

Why don't you send an WRQ packet to your own UDP port 69 to see if it returns an ACK?


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites
ptrex

@

In the same exampke script you posted you could include a listener.

To see that you receive feedback from the server.

While (1)
        $srcv = UDPRecv($Socket, 69)
        If ($srcv <> "") Then
            ConsoleWrite("Received Response" & @CR)
            ConsoleWrite($srcv & @CR)
        EndIf
     sleep(100)
WEnd

In a normal good connection state you should get back a response like

Received Response
HTTP/1.1 200 OK

Then if this response is there you can perform an action in the script.

Regards,

ptrex

Share this post


Link to post
Share on other sites
enaiman

@CoePSX and ptrex

Thank you very much - I have never thought to do that. It is brilliant :P

edit:

tried the following code:

UDPStartup()
$socket = UDPOpen("192.168.0.30", 69)
While (1)
    $status = UDPSend($socket, "Message")
    If $status = 0 then 
        MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
        Exit
    EndIf
     ;sleep(100)
    $srcv = UDPRecv($Socket, 200)
    If ($srcv <> "") Then
        ConsoleWrite("Received Response" & @CR)
        ConsoleWrite($srcv & @CR)
        ExitLoop
    EndIf
    sleep(100)
WEnd
UDPCloseSocket($socket)
UDPShutdown()

the UDPSend is working fine, I can see the result on my TFTP server (aborted requests) but UDPReceive returns nothing, any ideas?

Thanks,

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
ptrex

@enaiman

This works on my network.

#include <string.au3>

Dim $Broadcast

$Broadcast = "10.0.0.X" ; Your address here
$Port = 69 ; UDP 69  = TFTP port

UDPStartUp()

$Start = 1

$Socket = UDPopen($Broadcast, $Port)

ConsoleWrite($Socket[1] & "|" & $Socket[2] & "|" & $Socket[3] & @LF & @LF)

$cmd  = 'PING ICMP' & @CRLF
;$cmd &= 'HOST:239.255.255.250:69' & @CRLF
$cmd &= @CRLF

ConsoleWrite($cmd & @LF& @LF)

UDPSend($Socket, $cmd)

_StartListener()
sleep (2000)

Func _StartListener()
If $Start = 1 Then
    $i = 0
    While (1)
        $srcv = UDPRecv($Socket, 2048)
        If ($srcv <> "") Then
            ConsoleWrite("Received Response" & @CR)
            ConsoleWrite($srcv & @CR)
            ConsoleWrite(_HexToString(Stringmid($srcv,9)) & @CR)

        EndIf
     sleep(100)
    WEnd
EndIf
EndFunc


Func OnAutoItExit()
    UDPCloseSocket($Socket)
    UDPShutdown()
EndFunc

But beaware that the returned data might be HEX data. When testing this the HEXToString function is bugged in AU3.

See bug Report where I posted a fix for this.

Regards

ptrex

Share this post


Link to post
Share on other sites
enaiman

@ptrex

Thank you, I really appreciate it.

I will test the code on Monday and I'll let you know about the outcome.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
ptrex

Share this post


Link to post
Share on other sites
hellAT

hm, is tftp (what should be checked) running on the pc where the script is running? that it might be enought to use a netstat...

"netstat -an -p udp | findstr :69"

and look in the result...

/Karsten

Share this post


Link to post
Share on other sites
enaiman

@ptrex and hell@wurstgurke.de

Gentlemen, thank you very much for your help,

Both examples work very nice ;)

:P


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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  

×