[实践OK]Linux下的netstat查看所有端口/TCP/UDP端口常用参数总结。

jackxiang 2018-7-15 09:28 | |
netstat -lntp   #常用命令参数及解释如下:主要是看IP和TCP,以及程序的PID。
-l, --listening            display listening server sockets
-n, --numeric              don't resolve names
-t, tcp
-p, --program
   Show the PID and name of the program to which each socket belongs.


一)netstat常用查看端口参数之查看所有tcp/udp端口:
netstat -atlunp|grep 80


二)netstat常用查看端口参数之单独查看tcp/udp端口命令:
netstat -uln

Proto Recv-Q Send-Q Local Address               Foreign Address             State
udp        0      0 0.0.0.0:111                 0.0.0.0:*
udp        0      0 0.0.0.0:808                 0.0.0.0:*
udp        0      0 127.0.0.1:837               0.0.0.0:*
udp        0      0 0.0.0.0:17617               0.0.0.0:*
udp        0      0 0.0.0.0:2392                0.0.0.0:*



假如没有n,直接用netstat -tl,显示的是一些端口的程序名,如下:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 *:5646                      *:*                         LISTEN
tcp        0      0 *:sunrpc                    *:*                         LISTEN
tcp        0      0 *:7824                      *:*                         LISTEN
tcp        0      0 *:webcache                  *:*                         LISTEN
tcp        0      0 *:ssh                       *:*                         LISTEN
tcp        0      0 *:5881                      *:*                         LISTEN

三)netstat常用查看端口参数之单独查看tcp端口命令:
netstat -tln

Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:34945               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:32740               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:15770             0.0.0.0:*                   LISTEN

四)netstat本身也是通过读取系统中的/proc/net/tcp(6)文件来实现对当前网络状态的监控输出的
netstat本身也是通过读取系统中的/proc/net/tcp(6)文件来实现对当前网络状态的监控输出的。我们只要依样画葫芦对此文件进行 解析(主要是合并ipv4和ipv6的内容,然后从16进制转换成字符串形式的ip,端口),然后再比对一下,只要发现此socket的远程ip和端口和 php中的$_SERVER['REMOTE_ADDR'],$_SERVER['REMOTE_PORT']相匹配即可。具体实现如下:

摘录:http://www.4shell.org/archives/2064.html
参考:http://www.80sec.com/security-issue-on-linux-fd-inheritance.html

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/9821/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2023-3-29 09:47
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]