Saturday 2 November 2013

How to get hostname by IP and get IP by hostname in python


  • If you have IP address and you want hostname in network then
 from socket import *
 hostname=getfqdn(‘192.168.1.13’) 

         it will give you hostname of computer

  • If you want hostname from IP address then
 from socket import *
 ip=gethostbyname_ex(‘hostname’)[2][0]
 
          It will provide IP address of hostname

No comments:

Post a Comment