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