python 批量处理(通过ip地址获取机器名) 20
需求:有一个ip的txt文本,通过修改以下代码实现生成一个txt文本,并且文本里是获取到的机器名。ip.txt文本:192.168.1.0192.168.1.254192...
需求:有一个ip的txt文本,通过修改以下代码实现 生成一个txt文本,并且文本里是获取到的机器名。
ip.txt文本:
192.168.1.0
192.168.1.254
192.152.1.1
......
代码:
import sys, socket
try:
result = socket.gethostbyaddr("66.249.71.15")
print "Primary hostname:"
print " " + result[0]
# Display the list of available addresses
#that is also returned
print "\nAddresses:"
for item in result[2]:
print " " + item
except socket.herror, e:
print "Couldn't look up name:", e 展开
ip.txt文本:
192.168.1.0
192.168.1.254
192.152.1.1
......
代码:
import sys, socket
try:
result = socket.gethostbyaddr("66.249.71.15")
print "Primary hostname:"
print " " + result[0]
# Display the list of available addresses
#that is also returned
print "\nAddresses:"
for item in result[2]:
print " " + item
except socket.herror, e:
print "Couldn't look up name:", e 展开
1个回答
展开全部
import sys, socket
try:
ipLines = open('ip.txt').readlines()
results = []
for ip in ipLines:
result = socket.gethostbyaddr(ip.replace('\n',''))
results.append(result[0])
print "Primary hostname:"
print " " + result[0]
print "\nAddresses:"
for item in result[2]:
print " " + item
wr = open('hostname.txt','w+')
for host in results:
wr.write(host)
wr.write('\n')
wr.close()
except socket.herror, e:
print "Couldn't look up name:", e
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |