如何找出某个地址范围内有多少客户端?

发布于 2024-10-02 04:30:07 字数 130 浏览 12 评论 0原文

我尝试用谷歌搜索这个,但没有找到任何东西...我正在构建一个端口扫描仪,我想这样做,我可以扫描一个网络范围,例如 192.168.2.* 并找出该网络上有多少台计算机在线范围。很像Nmap。我正在用 python 编程。这在Python中可能吗?

I tried googling for this but i didnt find anything... I am building a port scanner and i would like to make it so, that i can scan a network range e.g 192.168.2.* and find out how many computers are on that range that are online. Alot like Nmap. I am programming in python. Is this possible in Python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤千羽 2024-10-09 04:30:07

使用 python-nmap。基本用法:

import nmap
nm = nmap.PortScanner()
nm.scan(hosts='192.168.2.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
for host, status in hosts_list:
    print('{0}:{1}'.format(host, status))

更多参考请参见 http://pypi.python.org/pypi/python-nmap< /a>

Use python-nmap. Basic usage:

import nmap
nm = nmap.PortScanner()
nm.scan(hosts='192.168.2.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
for host, status in hosts_list:
    print('{0}:{1}'.format(host, status))

For further reference see http://pypi.python.org/pypi/python-nmap

感受沵的脚步 2024-10-09 04:30:07

这是草案示例,您可以从以下开始:

import socket

addr_range = "192.168.1.%d"

ip_address_up = []

# Use UDP. 
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

s.settimeout(2.0)

for i in range(1, 254):
    try:
        ip = addr_range % i
        socket.gethostbyaddr(ip)
        ip_address_up.append(ip)
    except socket.herror as ex:
        pass

print ip_address_up

或使用 ICMP 进行类似的操作 (ping)更感谢 UDP:

import socket
import ping

ip_address_up = []

addr_range = "192.168.1.%d"

for i in range(1, 254):       
   try:
       ip = addr_range % i
       delay = ping.do_one(ip, timeout=2)
       ip_address_up.append(ip)
   except (socket.herror, socket.timeout) as ex:
       pass

print ip_address_up

Here is Draft example that you can start with:

import socket

addr_range = "192.168.1.%d"

ip_address_up = []

# Use UDP. 
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

s.settimeout(2.0)

for i in range(1, 254):
    try:
        ip = addr_range % i
        socket.gethostbyaddr(ip)
        ip_address_up.append(ip)
    except socket.herror as ex:
        pass

print ip_address_up

or something like this using ICMP (ping) rather thank UDP:

import socket
import ping

ip_address_up = []

addr_range = "192.168.1.%d"

for i in range(1, 254):       
   try:
       ip = addr_range % i
       delay = ping.do_one(ip, timeout=2)
       ip_address_up.append(ip)
   except (socket.herror, socket.timeout) as ex:
       pass

print ip_address_up
神回复 2024-10-09 04:30:07

使用 原始套接字 你可以实现类似 nmap 的东西。您可能会发现,与正常的编程接口相比,需要使用特制的数据包来制作信息最丰富的探测,这些数据包会做“奇怪”的事情。 IP/UDP/TCP RFC 非常值得阅读。

使用原始套接字,您可以逐字节生成您选择的任何探测数据包,并设置在正常情况下通常不可能/很难做到的选项/配置,但会“欺骗”主机泄露大量信息。

Using raw sockets you can implement something nmap-like. You will probably find that the most informative probes need to be made using specially crafted packets that do "odd" things, compared to normal programming interfaces. It's well worth reading up on the IP/UDP/TCP RFCs.

Using raw sockets you can generate byte by byte any probing packet of your choosing, with options/configurations set that are normally impossible/hard to do under normal circumstances, but which "trick" a host into revealing a wealth of information.

溺ぐ爱和你が 2024-10-09 04:30:07

对于本地网络上的 IPv4,您可以使用 ARP 使用 Scapy查看相关问题

For IPv4 on local net you can resort to ARP using say Scapy, see related question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文