数百个IP地址的状态检查器 [英] Status checker for hundreds IP addresses

查看:93
本文介绍了数百个IP地址的状态检查器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何制作一个状态检查器,在几分钟内检查大约500个地址吗? (它会检查某个端口是否在监听).

I wonder how to make a status checker, checking about 500 addresses in a few minutes? (it'll check a certain port if its listening).

但是我关心性能...所以我不知道它是否可以用PHP完成.等待着您的建议.

But I care about the performance... so I don't know if it can be done with PHP. Waiting for your suggestions guys.

如果您认为最好的方法是PHP或C#,也请给我一些示例.

Also please give me some examples, if you think that the best way for this thing will be PHP or C#.

Ofc.我的意思是TCP连接,但不是http,因为我需要检查打开的端口,例如: 11740

Ofc. I meant the TCP connection but not http, since I need to check open port for example: 11740

为此问题增加了第三笔赏金!请发布比已经发布的答案更好的答案.

Added third bounty for this question! Please post some better answer than those already posted.

推荐答案

最好的方法是 nmap ,如其他答案中所述.

The best way to this would be nmap, as mentioned in other answers.

您要像这样运行它(-PN不ping,-sP表示跳过端口扫描,仅检查主机是否启动,-PS80表示检查端口80,-n不执行反向DNS查找,-oG -以机器可读格式输出,其他参数是IP地址或主机名):

You'd want to run it like this (-PN is don't ping, -sP means to skip the port scan and just check if the host is up, -PS80 means to check port 80, -n is not to do reverse DNS lookup, -oG - is to output in machine readable format, and the other arguments are IP addresses or hostnames):

nmap -PN -sP -PS80 -n -oG - --send-ip IP1 IP2 ...

它看起来像这样:

$ nmap -n -PN -sP -PS80 -oG -  209.85.147.104 87.248.122.122 4.4.4.4
# Nmap 5.21 scan initiated Tue Feb 21 01:07:20 2012 as: nmap -n -PN -sP -PS80 -oG - 209.85.147.104 87.248.122.122 4.4.4.4 
Host: 209.85.147.104 () Status: Up
Host: 87.248.122.122 () Status: Up
Host: 4.4.4.4 ()    Status: Down
# Nmap done at Tue Feb 21 01:07:21 2012 -- 3 IP addresses (2 hosts up) scanned in 0.95 seconds

您可以毫无问题地从PHP运行并解析它.我对PHP不太有经验,也没有测试过,但是这里有一些示例代码:

You could run and parse this from PHP with no trouble. I'm not very experienced in PHP, and haven't tested this, but here's some example code:

<?php
$output = shell_exec('nmap -n -PN -sP -PS80 -oG - --send-ip ' . implode(" ", $ips));
$result = array();
foreach(preg_split("/\r?\n/", $output) as $line) {
    if (!(substr($line, 0, 1) === "#")) {
        $info = preg_split("[\t ]", $line);
        $result[$info[2]] = ($info[5] === "Up");
    }
}
?>

介意的是,编写PHP代码或C#代码或执行此操作没什么大不了的,只是nmap非常擅长于此,并且用途极为广泛,编写此代码的目的是重新发明轮子.如果您决定走这条路,请确保使代码异步,否则一台速度慢的服务器会减慢整个扫描的速度.

Mind you, writing PHP code or C# code or whatever that does this isn't a big deal, it's just that nmap is very very good at what it does, and extremely versatile, that writing code that does this is reinventing the wheel. If you do decide to go that route, make sure you make your code asynchronous, otherwise one slow server would slow down your entire sweep.

这篇关于数百个IP地址的状态检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆