Python Gets the Web site IP as well as the server

Source: Internet
Author: User
Tags get ip

Write a website to identify the IP and server code, compare rotten, hope the big guy advice

1 ImportRequests2 ImportSYS3 ImportSocket4 5 defget_ip (URL): # Get IP6     if 'http' inchstr (URL):7url = url.split ('//') [1]8IP =socket.gethostbyname (URL)9     Else:TenIP =socket.gethostbyname (URL) One     returnIP A  - defget_server (URL): # Get Server -     if 'http' inchstr (URL): theHttp_url =URL -Https_url =URL -     Else: -Http_url ='/ http'+str (URL) +Https_url ='https://'+str (URL) -     Try: +Re_header =Requests.get (http_url). Headers A     except: atRe_header =Requests.get (https_url). Headers -     Try: -Server = re_header['Server'] -     except: Server ='Unknow' -     returnServer -  in  - if __name__=="__main__": to     ifSYS.ARGV[1] = ='- R': +With open (sys.argv[2]) as F: -              forLineinchF: theline =Line.strip () *                 Try: $TARGET_IP =get_ip (line)Panax NotoginsengServer =Get_server (line) -                     Print("Website:", line) the                     Print("-------------IP:"+target_ip+"-------------") +                     Print('Server:', Server,'\ n') A                 except:Print("Website:", line,"can ' t visit\n") the     Else: +URL = sys.argv[1] -         Try: $TARGET_IP =get_ip (URL) $Server =get_server (URL) -             Print("Website:", URL) -             Print("-------------IP:"+target_ip+"-------------") the             Print('Server:', Server,'\ n') -         except:Print("Website:"Url"can ' t visit\n")

used the Requests,socket,sys standard library

To operate on a single site:

To manipulate a text file:

Python Gets the Web site IP as well as the server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.