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 展开
展开全部
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组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询