Last active
May 23, 2018 06:58
-
-
Save Loveforkeeps/e05f9abdab233bc99c0e343e0edf91bd to your computer and use it in GitHub Desktop.
判断域名是http还是https
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# coding: utf-8 | |
# Author: EMo | |
import http.client,sys | |
def get_url(host): | |
""" 将域名转换为URL(是否协议与WWW判断) """ | |
global datas | |
conn = http.client.HTTPConnection(host,timeout=3) | |
try: | |
conn.request("HEAD",'') | |
except Exception as TE: | |
print(("1",host,TE)) | |
host = "www."+host | |
conn = http.client.HTTPConnection(host,timeout=3) | |
try: | |
conn.request("HEAD",'') | |
except Exception as TE: | |
print(("2",host,TE)) | |
try: | |
conn.getresponse() | |
ret = "http://"+host | |
except Exception as TE: | |
print(("3",host,TE)) | |
ret = "https://"+host | |
print(ret) | |
return ret | |
if __name__ == "__main__": | |
if len(sys.argv) > 1: | |
host = sys.argv[1] | |
else: | |
host = "loveforkeeps.top" | |
print(get_url(host)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment