-2

I'm trying to realize a little script in Autoit that retrieves all IPs used by Facebook servers (query "-i origin AS32934" to whois.radb.net, as developer page says), but I don't understand why WhoIs servers are not responding to my queries. This is the script:

Local $host = "whois.radb.net", $query = "-i origin AS32934"
If Ping($host) Then
 $ws = DllOpen("ws2_32.dll")
 TCPStartup()
 $ip = TCPNameToIP($host)
 If @error Then _err("TCPNameToIP", @error)
 Global $socket = TCPConnect($ip, 43)
 If @error Then _err("TCPConnect", @error)
 TCPSend($socket, $query)
 If @error Then _err("TCPSend", @error, 1)
 Local $text = "", $t = TimerInit(), $counter = 0

 While 1
    $recv = TCPRecv($socket, 2048)
    If @error And @error <> -1 Then
        $aRet = DllCall($ws, "int", "WSAGetLastError")
        MsgBox(16,"ERROR", "Function: TCPRecv" & @CRLF & "Last data received: " & $recv & @CRLF & "Winsock error: " & $aRet[0] & @CRLF & "Loop executed " & $counter & " times")
        ExitLoop
    EndIf
    $text &= $recv
    $counter += 1
    If TimerDiff($t) > 4999 Then ExitLoop
 WEnd

 If $text = "" Then
    MsgBox(48, "RESULT", "EMPTY" & @CRLF & "Loop executed " & $counter & " times")
 Else
    MsgBox(0, "RESULT", $text)
 EndIf

 TCPCloseSocket($socket)
 TCPShutdown()
Else
 _err("Ping", @error, 0)
EndIf

Func _err($func, $err, $opt = 2)
    MsgBox(16, "ERROR", "Function: " & $func & @CRLF & "Error: " & $err)
    If $opt = 1 Then TCPCloseSocket($socket)
    If $opt > 0 Then TCPShutdown()
    Exit
EndFunc

The output is always "RESULT:EMPTY". I've tried to query other WhoIs services with various queries (for example whois.verisign-grs.com with "=facebook.com") but I get no response. It's not a problem about my network, because I've tried a Nirsoft WhoIs tool ad it works. I've downloaded a sniffer and this is the output when I start my script:

==================================================
Protocol          : TCP
Local Address     : 192.168.1.101
Remote Address    : 198.108.0.18
Local Port        : 23509
Remote Port       : 43
Remote Host       : whois.radb.net
Service Name      : nicname
Packets           : 5  {5 ; 0}
Data Size         : 17 Bytes  {17 ; 0}
Total Size        : 274 Bytes  {217 ; 57}
Data Speed        : 0.0 KB/Sec
Capture Time      : 07/07/2014 15:18:37:313
Last Packet Time  : 07/07/2014 15:18:45:837
Duration          : 00:00:08.523
==================================================
Content:
-i origin AS32934

It seems the packet is sent but no packet is received.

j0kky
  • 85
  • 2
  • 8

1 Answers1

0

I just found out the solution: adding a @crlf at the end of TCPSend() request

$query = "-i origin AS32934" & @crlf
j0kky
  • 85
  • 2
  • 8