Sign in to follow this  
Followers 0
SpinningCone

help with telnet/tcp commands

4 posts in this topic

#1 ·  Posted (edited)

I'm trying to write a simple script which will connect to a computer via telnet, run a couple commands (ehlo/vrfy) and get back the results. the purpose being i need to do this to verify if something exists already.

I can get everything to work if i open a telnet window and manually do it but i want to be able to easily fire off this lookup tool as i need it.

here is my initial tcpconnect test code:

TCPStartup()
$ip = TCPNameToIP("$domain")
ConsoleWrite($ip & @CRLF)
$Socket = TCPConnect($ip, 25)
If $Socket = -1 Then
    ConsoleWrite('i die' & @crlf)
    Exit
EndIf
;
Sleep(500)
$recv = TCPRecv($Socket, 500)
$err = @error
If $recv <> "" then
ConsoleWrite('Received: ' & $recv & @crlf)
else
ConsoleWrite('got nothing? ' & $recv & ":: " & $err & @CRLF)
EndIf

$send = TCPSend($Socket, "help" & @CR)
$recv = TCPRecv($Socket, 500)
If $recv <> "" then
ConsoleWrite('Received: ' & $recv & "::" & $send & @crlf)
else
ConsoleWrite('got nothing? ' & $recv & " :: " & $send & @CRLF)
EndIf

TCPCloseSocket($Socket)
TCPShutdown ( )

the result of this block is :

###.##.###.###

got nothing? :: 0

got nothing? :: 5

so $socket exists. tcpsend is sending 5 bytes successfully and even though i'm not getting anything back TCPRecv() is not setting @error so technically it should be working too.

I can't seem to figure out why TCPRecv() isnt giving anything back but everything else seems successful.

Edited by SpinningCone

Share this post


Link to post
Share on other sites



I am currently at university right now so i cannot test your program ... however, what does the client code look like?... Are you sure it is properly sending the data? also are you sure you have the right port? <- if all is correct try a while loop on the receive to see if it could be a timing thing... altho it shouldt. Ill take a look when i get home...

Again if you do know the code for the client please post it. (ie the client should have a sort of tcpsend())

Share this post


Link to post
Share on other sites

there is no client. that's the whole code. i'm testing the connection .

tcpconnect() is returning a socket. tcpsend() is not setting @error and is returnign a success value (5 bytes) tcprecv() however is returning a blank ( "") but isnt setting @error so presumably it's successfull but i'm not getting anything back.

Share this post


Link to post
Share on other sites

nm I finally figured it out, tcp is just slow. sleep(500) wasnt enough. needed more like sleep(8000), as long as i don't get an error i put in a while loop that just keeps trying to receive until it gets something.

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  
Followers 0