惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - 懒牛拉车

xxx tmp Thinkphp 3.2 Cookie丢失导致中英文混排 第一个python自动化实例 Nginx配置文件下载 每次用npm都很烦人 js 判断mac地址是否为组播地址 项目在本地时,css/js文件在浏览器刷新时,从(memory cache)读取,放服务器上就不会 模拟json_decode解析非法utf-8编码字符串 thinkphp3.2.2 CheckLangBehavior.class中,使用session无效原因分析 Thikphp 3.2 session页面传递失败问题 火狐autocomplete="off"无效 testlink windows 安装笔记 宝塔面板部署thinkcmf问题 coreseek 測試用例 coreseek 基与Sphinx 的全文索引 centos6 nginx 配置本地https访问 centos6 nginx安装好以后,添加拓展ssl centos6 php7 安装 memcache 和 memcached - 懒牛拉车 centos7 搭建 php7 + nginx (2) - 懒牛拉车 centos7 搭建 php7 + nginx (1)
php socket 循环ping ip,显示能ping通的IP地址
懒牛拉车 · 2021-05-13 · via 博客园 - 懒牛拉车

预览

index.php 代码

<?php
function ping2($host) {
    $port = 80;
    $buff = "123456789"; //测试字符串

    // ipv6
    //$socket = @socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP);

    // ipv4
    $socket = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    //发送超时1秒
    socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" => 0));
    //接收超时1秒
    socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array("sec" => 1, "usec" => 0));

    if (!$socket) return false;
    
    @socket_sendto($socket, $buff, strlen($buff), 0, $host, $port);
    $read = array($socket);
    $write = NULL;
    $except = NULL;
    if (@socket_select($read, $write, $except, 1) > 0) {
        return true;
    } else {
        return false;
    }
    @socket_close($socket);
}


function ping($host) {
    $icmp_socket = socket_create(AF_INET, SOCK_RAW, 1);
    socket_set_block($icmp_socket);
    socket_set_option($icmp_socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" => 0));

    /* connect to socket */
    socket_connect($icmp_socket, $host, null);

    /* 创建一个发送包*/
    $request = "\x08\x00\x19\x2f\x00\x00\x00\x00\x70\x69\x6e\x67";

    socket_send($icmp_socket, $request, strlen($request), 0);

    if (@socket_read($icmp_socket, 255)) {
        return true;
    } else {
        return false;
    }
    socket_close($icmp_socket);
}

$ip = $_GET['ip'];
if ($ip) {
    $result = ping($ip);
    if ($result) {
        echo "success";
    }
} else {
    $base = $_GET['base'] ?: "192.168.1";
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Ping</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<!-- 
url访问方式:
http://localhost/ping.php
http://localhost/ping.php?base=192.168.137
-->
<script type="text/javascript">
    $(function () {
        var num = 1;
        var ticket = setInterval(function () {
            if (num > 255) {
                clearInterval(ticket);
                return false;
            }
            var ip = '<?=$base?>.' + num;
            $.get("/ping.php?ip=" + ip, function (data) {
                console.log(data)
                if (data === 'success') {
                    $("body").append(ip + "<br/>")
                }
            })
            num++;
        }, 200)
    })
</script>
</body>
</html>
<?php } ?>