Python獲取指定網(wǎng)段正在使用的IP
#!/usr/bin/env python# -*- coding: utf-8 -*-’’’’’ 使用方法樣例 python test20.py 192.168.1.1 (會掃描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 ,然后掃描整個段所有地址 ’’’ 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)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. JS中6個對象數(shù)組去重的方法2. Java commons-httpclient如果實現(xiàn)get及post請求3. 資深程序員:給Python軟件開發(fā)測試的25個忠告!4. 一文帶你徹底理解Java序列化和反序列化5. PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(二)6. PHP利用curl發(fā)送HTTP請求的實例代碼7. Python基于requests庫爬取網(wǎng)站信息8. vscode運行php報錯php?not?found解決辦法9. PHP laravel實現(xiàn)導(dǎo)出PDF功能10. python中文本字符處理的簡單方法記錄

網(wǎng)公網(wǎng)安備