使用pytho读取一个ip列表文本,批量获取whois输出并写入到一个文本
python
import socket
if __name__ == '__main__':
# 江苏电信DNS地址
mylog = open('whois.log', mode = 'a',encoding='utf-8')
for line in open("ip.txt"):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('whois.apnic.net', 43))
print(line)
s.send(line.encode())
#s.send(b'192.168.198.2\r\n')
result = bytearray()
while True:
data = s.recv(10000)
if not len(data):
break
result.extend(data)
print(bytes(result).decode('ascii'))
print(bytes(result).decode('ascii'), file=mylog)
s.close()
mylog.close()
print("------------------done------------------")
!