最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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)文章

最新評論

华容县| 青川县| 张家港市| 衡阳市| 呈贡县| 招远市| 韶关市| 日喀则市| 洛南县| 竹山县| 清水县| 衡阳县| 繁峙县| 大田县| 宁津县| 紫金县| 山西省| 阿拉善盟| 大丰市| 康保县| 石屏县| 荃湾区| 龙游县| 友谊县| 庄河市| 安塞县| 丹寨县| 玉林市| 新干县| 宣武区| 花莲县| 福贡县| 溆浦县| 津南区| 徐闻县| 山东| 佛坪县| 宾阳县| 老河口市| 项城市| 浮山县|