j0kky Posted July 2, 2014 Share Posted July 2, 2014 (edited) 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 July 3, 2014 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
j0kky Posted July 3, 2014 Author Share Posted July 3, 2014 I begin to think there are huge compatibility problems between TCP and Windows 7 Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
j0kky Posted July 4, 2014 Author Share Posted July 4, 2014 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. Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
ripdad Posted July 4, 2014 Share Posted July 4, 2014 TCPRecv()should be fixed in the next version. Try this for now:While 1 $recv = TCPRecv($socket, 2048) If (@error < -1) Or (@error > 0) Then "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 More sharing options...
ripdad Posted July 4, 2014 Share Posted July 4, 2014 (edited) 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 July 4, 2014 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 More sharing options...
j0kky Posted July 4, 2014 Author Share Posted July 4, 2014 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? Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
Solution j0kky Posted July 9, 2014 Author Solution Share Posted July 9, 2014 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() Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now