python获取他人的ip_Python获取指定网段正在使用的IP

#!/usr/bin/env python

# -*- coding: utf-8 -*-

'''''

使用方法样例 python test20.py 192.168.1.1

(会扫描192.168.1.1-255的ip)

多线程加速后大概十几秒

'''

import platform

import sys

import os

import time

import threading

live_ip = 0

def get_os():

os = platform.system()

if os == "Windows":

return "n"

else:

return "c"

def ping_ip(ip_str):

cmd = ["ping", "-{op}".format(op=get_os()),

"1", ip_str]

output = os.popen(" ".join(cmd)).readlines()

for line in output:

if str(line).upper().find("TTL") >= 0:

print("ip: %s is ok ***" % ip_str)

global live_ip

live_ip += 1

break

def find_ip(ip_prefix):

'''''

给出当前的127.0.0 ,然后扫描整个段所有地址

'''

threads = []

for i in range(1, 256):

ip = '%s.%s' % (ip_prefix, i)

threads.append(threading.Thread(target=ping_ip, args={ip, }))

for i in threads:

i.start()

for i in threads:

i.join()

if __name__ == "__main__":

print("start time %s" % time.ctime())

cmd_args = sys.argv[1:]

args = "".join(cmd_args)

ip_pre = '.'.join(args.split('.')[:-1])

find_ip(ip_pre)

print("end time %s" % time.ctime())

print('本次扫描共检测到本网络存在%s台设备' % live_ip)

以上就是Python获取指定网段正在使用的IP的详细内容,更多关于python 获取网段ip的资料请关注脚本之家其它相关文章!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值