Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whois query works with telnet but not netcat

Tags:

netcat

whois

I am trying to write an advanced whois client, so I have been experimenting with sending commands to whois servers using netcat (nc) in Arch Linux. For example, this works great:

$ echo domain google.com | nc whois.crsnic.net 43
# => nc outputs whois data for google.com

However, the whois server that handles suffixes like .br.com is whois.centralnic.net and that server seems to not work with netcat. When I give it any query, it seems to simply close the connection without a response:

$ echo foobar | nc whois.centralnic.net 43
# => No output from nc.

I successfully made the same query using telnet:

$ telnet whois.centralnic.net 43
Trying 193.105.170.136...
Connected to whois.centralnic.net.
Escape character is '^]'.
foobar
DOMAIN NOT FOUND
Connection closed by foreign host.

So what could possibly make a server behave differently for telnet than netcat?

I thought maybe it was a timing issue, so I unsuccessfully tried:

$ { sleep 4; echo foobar; sleep 4; } | nc whois.centralnic.net 43
# => No output from nc.

I saw that netcat has a -T option to make it behave more like telnet, so I unsuccessfully tried:

$ { sleep 4; echo foobar; sleep 4; } | nc -T whois.centralnic.net 43
# => No output from nc.

In my production system I will not be using netcat or telnet, but there seems to be some strange networking issue happening here and I would like to be aware of it. Can anyone shed some light on why netcat would work for all the whois servers but only telnet will work for whois.centralnic.net?

like image 527
David Grayson Avatar asked May 12 '13 06:05

David Grayson


1 Answers

The service expects CRLF in its request, not just LF;

This works (on Ubuntu, there are multiple netcat versions, so can't speak for yours)

$ echo -e "foobar\r\n" | nc whois.centralnic.net 43
DOMAIN NOT FOUND
like image 87
Joachim Isaksson Avatar answered Oct 19 '22 15:10

Joachim Isaksson