Python獲取指定網(wǎng)段正在使用的IP
#!/usr/bin/env python# -*- coding: utf-8 -*-’’’’’ 使用方法樣例 python test20.py 192.168.1.1 (會(huì)掃描192.168.1.1-255的ip) 多線程加速后大概十幾秒’’’import platformimport sysimport osimport timeimport threadinglive_ip = 0def 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 breakdef find_ip(ip_prefix): ’’’’’ 給出當(dāng)前的127.0.0 ,然后掃描整個(gè)段所有地址 ’’’ 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(’本次掃描共檢測(cè)到本網(wǎng)絡(luò)存在%s臺(tái)設(shè)備’ % live_ip)
以上就是Python獲取指定網(wǎng)段正在使用的IP的詳細(xì)內(nèi)容,更多關(guān)于python 獲取網(wǎng)段ip的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. XML入門(mén)的常見(jiàn)問(wèn)題(三)2. .NET Core 分布式任務(wù)調(diào)度ScheduleMaster詳解3. 不要在HTML中濫用div4. HTML5實(shí)戰(zhàn)與剖析之觸摸事件(touchstart、touchmove和touchend)5. CSS清除浮動(dòng)方法匯總6. HTTP協(xié)議常用的請(qǐng)求頭和響應(yīng)頭響應(yīng)詳解說(shuō)明(學(xué)習(xí))7. XML在語(yǔ)音合成中的應(yīng)用8. ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫(xiě)金額)的函數(shù)9. XML 非法字符(轉(zhuǎn)義字符)10. jscript與vbscript 操作XML元素屬性的代碼
