python module for nslookup

后端 未结 9 829
渐次进展
渐次进展 2020-12-10 00:27

Is there a python-module that\'s doing the same stuff as nslookup does? I am planning to use nslookup on digging some information regarding the domain of a URL to be scrappe

9条回答
  •  失恋的感觉
    2020-12-10 01:31

    Note that socket.getfqdn() can return the full-qualified name of a hostname. See: http://docs.python.org/2/library/socket.html?highlight=socket.getaddrinfo#socket.getfqdn

    For example:

    python -c  'import socket; print(socket.gethostname()); print(socket.getfqdn());'
    myserver
    myserver.mydomain.local
    

    But the result depends the /etc/hosts configuration. If you have:

    $ cat /etc/hosts
    127.0.0.1       myserver  localhost.localdomain  localhost
    

    The result of socket.getfqdn() will be:

    python -c  'import socket; print(socket.getfqdn());'
    localhost.localdomain
    

    Oooops! To solve that, the only solution I know is to change the /etc/hosts as follow:

    $ cat /etc/hosts
    127.0.0.1       myserver  myserver.mydomain.local  localhost.localdomain  localhost
    

    Hope it helps!

提交回复
热议问题