Jump to content

Whois problem


Go to solution Solved by j0kky,

Recommended Posts

Hi guys,

I've tried some difficults realizing a simple whois from whois.radb.net. I've tried to query "-i origin AS32934", the right way to retrieve all FB IPs (as developer page says) but I really don't understand what is wrong with my script:

$ws = DllOpen("ws2_32.dll")
TCPStartup()
$ip = TCPNameToIP("whois.radb.net")
$socket = TCPConnect($ip, 43)
TCPSend($socket, "-i origin AS32934")
Local $text

While 1
    $recv = TCPRecv($socket, 2048)
    If @error Then
        $aRet = DllCall($ws, "int", "WSAGetLastError")
        MsgBox(0,$recv,$aRet[0])
        ExitLoop
    EndIf
    If $recv <> "" Then
        $text &= $recv
    EndIf
WEnd
ConsoleWrite(@CRLF & $text & @CRLF)
TCPCloseSocket($socket)
TCPShutdown()

The loops ends as soon as TCPRecv is called... and WSAGetLastError reports no error! :(

Thanks to all

Edited by j0kky
Link to comment
Share on other sites

Some news: I've downloaded a sniffer and I've seen that the outgoing packet containing "-i origin AS32934" is sent to the right ip, but no packets is received. I've tried to do a whois to Verisign too but same story...

Maybe is it a problem about my network? No!

I've downloaded a whois command line executable (from nirsoft) and that tool works without problem.

I think there is some problem with TCPRecv.

Link to comment
Share on other sites

Actually, the better way to do it is:

While 1
    $recv = TCPRecv($socket, 2048)
    If @error Then
        $aRet = DllCall($ws, "int", "WSAGetLastError")
        If @error Or ($aRet[0] <> 0) Then ExitLoop
    EndIf
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Your code doesn't work, I think the correct line is

If @error And @error <> -1 Then 

(In the same time you posted I was reading this thread), I think the better solution to solve TCPRecv bug is:

$ws = DllOpen("ws2_32.dll")
TCPStartup()
$ip = TCPNameToIP("whois.radb.net")
$socket = TCPConnect($ip, 43)
TCPSend($socket, "-i origin AS32934")
Local $text, $t = TimerInit()

While 1
    $recv = TCPRecv($socket, 2048)
    If @error And @error <> -1 Then
        $aRet = DllCall($ws, "int", "WSAGetLastError")
        MsgBox(0,$recv,$aRet[0])
        ExitLoop
    EndIf
    If $recv <> "" Then
        $text &= $recv
    EndIf
    If TimerDiff($t) > 9999 Then ExitLoop
WEnd
ConsoleWrite(@CRLF & $text & @CRLF)
TCPCloseSocket($socket)
TCPShutdown()

However it doesn't work at all with whois.radb.net, while if I try to connect to whois.verisign-grs.com, WSAGetLastError reports 10054 error: "Connection reset by peer", probably because of the timeout... Can you run with your pc this last script first with whois.radb.net and then with whois.verisign-grs.com?

Link to comment
Share on other sites

  • Solution

I found the solution: just add a @crlf after the request of TCPSend()

The final code is:

Local $host = "whois.radb.net", $query = "-i origin AS32934" & @CRLF
TCPStartup()
$ip = TCPNameToIP($host)
$socket = TCPConnect($ip, 43)
TCPSend($socket, $query)
Local $text = "", $t = TimerInit(), $i = 0
While $i < 200
$recv = TCPRecv($socket, 2048)
If @error And @error <> -1 Then
ExitLoop
EndIf
if $recv <> "" Then $text &= $recv
Sleep(10)
$i += 1
WEnd
ConsoleWrite($text & @CRLF)
TCPCloseSocket($socket)
TCPShutdown()
Link to comment
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
 Share

×
×
  • Create New...