dpevsxjn809817 2013-12-01 21:28
浏览 217

UDP端口扫描程序使用socket php

ok, it's easy to code TCP port scanner by using socket but i don't know why it's hard to be the same for UDP

I just want to check if a specific UDP port (say port 500) is open or not.

Here is my code:

$ip = '103.12.9.209';
$port = '500';

$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

$result = socket_connect($socket, $ip, $port);

if ($result)
{
    echo "Port is on";
}
else
{
    echo "Port is off";
}

socket_close($socket);

The problem is it always return true (port is on) even it's off.

What is the problem? any idea please?

Thanks.

  • 写回答

1条回答 默认 最新

  • dongshi3061 2013-12-01 22:04
    关注

    You need to send an empty UDP frame to the port in question and check for ICMP responses. If you get ICMP type 2, code 3 (port unreachable) then the port is closed. If you receive other codes like type3, code 1,2,9,10 or 13) the port is filtered. If you receive data or at least don't receive ICMP responses then it can be assumed that the port is open, but however, if there are just no ICMP responses it is not sure that the port is open.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog