#coding:utf-8 import socket def URL2IP():
for oneurl in urllist.readlines():
url=str(oneurl.strip())[7:]
print(url)
try:
ip =socket.gethostbyname(url)
print(ip)
iplist.writelines(str(ip)+"\n")
except:
print("this URL 2 IP ERROR ") try:
urllist=open("D:\urllist.txt","r")
iplist=open("D:\iplist.txt","w")
URL2IP()
urllist.close()
iplist.close()
print("complete !")
except:
print("ERROR !")
先上代码。刚刚军训完回来,在军训期间想写一个项目,所以就写了个域名解析主要用了socket里的gethostbyname来解析urllist.txt里的域名
然后解析完成后在写入到iplist.txt中
>>>运行>>>>>>