Python獲取指定網(wǎng)段正在使用的IP
更新時間:2020年12月14日 16:17:32 作者:清風(fēng)軟件測試
這篇文章主要介紹了Python獲取指定網(wǎng)段正在使用的IP的示例代碼,幫助大家更好的利用python進行測試,感興趣的朋友可以了解下
#!/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):
'''''
給出當(dāng)前的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('本次掃描共檢測到本網(wǎng)絡(luò)存在%s臺設(shè)備' % live_ip)

以上就是Python獲取指定網(wǎng)段正在使用的IP的詳細內(nèi)容,更多關(guān)于python 獲取網(wǎng)段ip的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
python3通過udp實現(xiàn)組播數(shù)據(jù)的發(fā)送和接收操作
這篇文章主要介紹了python3通過udp實現(xiàn)組播數(shù)據(jù)的發(fā)送和接收操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05
已安裝tensorflow-gpu,但keras無法使用GPU加速的解決
今天小編就為大家分享一篇已安裝tensorflow-gpu,但keras無法使用GPU加速的解決,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
Python數(shù)據(jù)結(jié)構(gòu)與算法之二叉樹結(jié)構(gòu)定義與遍歷方法詳解
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)與算法之二叉樹結(jié)構(gòu)定義與遍歷方法,結(jié)合實例形式詳細分析了Python實現(xiàn)二叉樹結(jié)構(gòu)的定義、遍歷方法及相關(guān)注意事項,需要的朋友可以參考下2017-12-12
使用Python批量刪除MySQL數(shù)據(jù)庫的全部外鍵
這篇文章主要為大家詳細介紹了如何使用Python批量刪除MySQL數(shù)據(jù)庫的全部外鍵,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-04-04

