Search code examples
pythonnetwork-programmingwhoispywhois

How to use WHOIS queries from python script when port 43 is likely not accessible


Im very new to network programming and faced a following problem:

Im working on VMware CentOS7 virtual machine on Windows10 host. My script should send WHOIS queries and parse their output (e.g. expiration date).

However, an attempt to send a query leads to a connection error:

>>>import whois
>>>whois.query('google.com')


WhoisCommandFailed: connect: Network is unreachable

I tried to whois from terminal, but error was the same. When i tried to use whois directly from Windows, which hosts virtual machine, the error seemed to look same as well (connection timeout).

As i found out, it was most likely related to access to port 43. I created rules (for in and out) for Windows firewall for this port by a guide , but error still persisted. It looks like access to this port was blocked by ISP (however ping command is working).

To sum up, I got two questions there: 1) (less important) How to check if port 43 is blocked by firewall either by ISP? 2) (most important) Is it possible somehow to reconfigure WHOIS for usage of another port (i.e. 23) for sending queries by Python script?
Unfortunately, ISP security policy doesn't allow them to open 43 port.


Solution

  • Mostly ISP doesn't block any port but yes, this is not 100% true.

    Testing connection:

    • run tcpdump (install command: yum install tcpdump) command on CentOS: tcpdump -peni any tcp and port 43
    • You have to see lines with the following text: 192.168.1.1.57350 > 192.34.234.30.43 where 192.34.234.30 IP address means the remote whois server.
    • Try to telnet to remote server's TCP/43 port: telnet 192.34.234.30 43
    • You should see the following:

    Trying 192.34.234.30...

    Connected to 192.34.234.30.

    Escape character is '^]'.

    • If you can`t see context like that and you get back prompt immediately you will a firewall rule somewhere what is block connection. I recommend to switch off firewall temporarily and test again.

    You cannot change port number, because it is configured on the remote side, on the server.

    Can CentOS7 server communicate towards the internet? In example can you install packages?

    Is there any router between windows machine and ISP?