幽灵资源网 Design By www.bzswh.com
#!/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的详细内容,更多关于python 获取网段ip的资料请关注其它相关文章!

标签:
python,网段,python,获取网段IP

幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?