0
아래의 스크립트를 작성했는데 정상적으로 작동합니다. 그러나 생산량은 우호적이지 않습니다 (아래 참조). 나는, '[], 제안하십시오 첫 번째 줄은 호스트 이름과 IP를 표시하고 (제거 할python - print output
('testhostname', [], ['10.10.10.10'])
cannot resolve hostname: 10.10.10.11
import socket
pfile = open ('C:\\Python27\\scripts\\test.txt')
while True:
IP = pfile.readline()
if not IP:
break
try:
host = socket.gethostbyaddr(IP.rstrip())
print host
except socket.herror, err:
print "cannot resolve hostname: ", IP
pfile.close()
@Thomas :'gethostbyaddr'는 역방향 조회를 수행하고 별칭과 대체 IP와 함께 호스트 이름을 제공하므로 무의미하지 않습니다. [the docs] (http://docs.python.org/2/library/socket.html#socket.gethostbyaddr)를 참조하십시오. – Blckknght
맞아, 내 바보 같은 말을 지울거야. – Thomas