InfoSec Forums InfoSec Forums Programming Convert Host/Domain Name to IP Address on Python

This topic contains 1 reply, has 2 voices, and was last updated by  cyber ghost 1 month, 3 weeks ago.

  • Author
    Posts
  • #3797

    ddos-admin
    Keymaster
    • Topics:11
    • Comments:7
    • Newbie

    Here is simple python code for converting a domain to IP Address

    screenshot-from-2016-11-17-02-40-51

    #!/usr/bin/python
    import socket
    import urlparse
    def getIp(domain):
          trytime = 0
          while True:
                     try:
                          domain = domain.split(‘:’)[0]
                          myaddr = socket.getaddrinfo(domain,None)[0][4][0]
                          return myaddr
                     except:
                          trytime+=1
                          if trytime>3:
                          return “”

    if __name__==’__main__’:
           www = “http://kali-linux.co”
           hosts = urlparse.urlsplit(www)
           if “:” in hosts.netloc:
                 host = hosts.netloc.split(“:”)[0]
                 port = hosts.netloc.split(“:”)[1]
           else:
                 host = hosts.netloc
                 port = ’80’
                 print getIp(host)

  • #4016

    cyber ghost
    Participant
    • Topics:1
    • Comments:12
    • Newbie

    Hello sir , I am kavish tyagi

    I have a question that I am beginners in pentesting and I am not good in Linux command so should you give m a way or prefer any book or something else by which I understand or learn the commands of Linux or Kali Linux .

    Plzzzzzz sir and sir thanku very much for sharing your knowledge with us thanku very much

    Waiting for postive reply sir..

You must be logged in to reply to this topic.