python获取他人的ip_Python获取指定网段正在使用的IP

 2023-09-07 阅读 26 评论 0

摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-'''''使用方法样例 python test20.py 192.168.1.1(会扫描192.168.1.1-255的ip)python爬虫更改ip。多线程加速后大概十几秒'''import platformimport sysimport osimport time一个网段多少ip地址

#!/usr/bin/env python

# -*- coding: utf-8 -*-

'''''

使用方法样例 python test20.py 192.168.1.1

(会扫描192.168.1.1-255的ip)

python爬虫更改ip。多线程加速后大概十几秒

'''

import platform

import sys

import os

import time

一个网段多少ip地址?import threading

live_ip = 0

def get_os():

os = platform.system()

if os == "Windows":

return "n"

python输入ip地址,else:

return "c"

def ping_ip(ip_str):

cmd = ["ping", "-{op}".format(op=get_os()),

"1", ip_str]

output = os.popen(" ".join(cmd)).readlines()

子网掩码和ip地址的关系。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

同一网段ip怎么设置?def find_ip(ip_prefix):

'''''

给出当前的127.0.0 ,然后扫描整个段所有地址

'''

threads = []

for i in range(1, 256):

python获取公网ip、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()

不同网段的ip怎么互通?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)

500个ip共一个网段如何设置。print("end time %s" % time.ctime())

print('本次扫描共检测到本网络存在%s台设备' % live_ip)

以上就是Python获取指定网段正在使用的IP的详细内容,更多关于python 获取网段ip的资料请关注脚本之家其它相关文章!

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/18865.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息