{"id":45796,"date":"2023-04-13T17:35:38","date_gmt":"2023-04-13T09:35:38","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=45796"},"modified":"2023-04-13T17:35:38","modified_gmt":"2023-04-13T09:35:38","slug":"lsof-netstat-nmap-port","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lsof-netstat-nmap-port.html","title":{"rendered":"\u51e0\u4e2a\u547d\u4ee4\u8f7b\u677e\u641e\u5b9alinux\u7684\u670d\u52a1\u72b6\u6001"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u9a8c\u8bc1\u54ea\u4e9b\u7aef\u53e3\u5728\u670d\u52a1\u5668\u7684\u7f51\u7edc\u63a5\u53e3\u4e0a\u5904\u4e8e\u76d1\u542c\u72b6\u6001\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u901a\u8fc7\u5f00\u653e\u7aef\u53e3\u7684\u72b6\u6001\u53ef\u4ee5\u68c0\u6d4b\u7f51\u7edc\u5165\u4fb5\u3001\u6392\u9664\u6545\u969c\u3001\u786e\u8ba4\u670d\u52a1\u5668\u4e0a\u7684\u7aef\u53e3\u5360\u7528\u7b49\u60c5\u51b5\u3002\u8fd9\u7bc7\u5feb\u901f\u6559\u7a0b\u4f1a\u4ecb\u7ecd\u4f7f\u7528 netstat \u3001 nmap \u548c lsof \u547d\u4ee4\u6765\u68c0\u67e5\u7aef\u53e3\u4f7f\u7528\u4fe1\u606f\u5e76\u627e\u51fa\u54ea\u4e9b\u7a0b\u5e8f\u6b63\u5728\u4f7f\u7528\u8fd9\u4e9b\u7aef\u53e3\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5982\u4f55\u68c0\u67e5 Linux \u4e2d\u7684\u7a0b\u5e8f\u548c\u76d1\u542c\u7684\u7aef\u53e3<\/strong><\/div>\n
1\u3001 \u6253\u5f00\u4e00\u4e2a\u7ec8\u7aef\uff0c\u5982 shell \u547d\u4ee4\u7a97\u53e3\u3002\r\n2\u3001 \u8fd0\u884c\u4ee5\u4e0b\u4efb\u610f\u4e00\u884c\u547d\u4ee4\uff1a<\/pre>\n

sudo lsof -i -P -n | grep LISTEN<\/p>\n

sudo netstat -tulpn | grep LISTEN<\/p>\n

sudo nmap -sTU -O IP\u5730\u5740<\/p><\/blockquote>\n

\u65b9\u5f0f 1\uff1alsof \u547d\u4ee4<\/strong><\/div>\n

\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n

$ sudo lsof -i -P -n\r\n$ sudo lsof -i -P -n | grep LISTEN\r\n$ doas lsof -i -P -n | grep LISTEN  ### OpenBSD\r\n<\/pre>\n

\u8f93\u51fa\u5982\u4e0b\uff1a
\n\"\"<\/p>\n

\u4ed4\u7ec6\u770b\u4e0a\u9762\u8f93\u51fa\u7684\u6700\u540e\u4e00\u884c\uff1a<\/p>\n

sshd    85379     root    3u  IPv4 0xffff80000039e000      0t0  TCP 10.86.128.138:22 (LISTEN)\r\nsshd \u662f\u7a0b\u5e8f\u7684\u540d\u79f0\r\n10.86.128.138 \u662f sshd \u7a0b\u5e8f\u7ed1\u5b9a (LISTEN) \u7684 IP \u5730\u5740\r\n22 \u662f\u88ab\u4f7f\u7528 (LISTEN) \u7684 TCP \u7aef\u53e3\r\n85379 \u662f sshd \u4efb\u52a1\u7684\u8fdb\u7a0b ID (PID)\r\n<\/pre>\n
\u65b9\u5f0f 2\uff1anetstat \u547d\u4ee4<\/strong><\/div>\n

\u4f60\u53ef\u4ee5\u5982\u4e0b\u9762\u6240\u793a\u4f7f\u7528 netstat \u6765\u68c0\u67e5\u76d1\u542c\u7684\u7aef\u53e3\u548c\u7a0b\u5e8f\u3002<\/p>\n

Linux \u4e2d netstat \u8bed\u6cd5<\/strong><\/span><\/div>\n
$ netstat -tulpn | grep LISTEN<\/pre>\n
FreeBSD\/MacOS X \u4e2d netstat \u8bed\u6cd5<\/strong><\/span><\/div>\n
$ netstat -anp tcp | grep LISTEN\r\n$ netstat -anp udp | grep LISTEN\r\n<\/pre>\n
OpenBSD \u4e2d netstat \u8bed\u6cd5<\/strong><\/span><\/div>\n
$ netstat -na -f inet | grep LISTEN\r\n\r\n$ netstat -nat | grep LISTEN\r\n<\/pre>\n
windows \u4e2d\u540c\u6837\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\uff1a<\/strong><\/span><\/div>\n
netstat -bano | more\r\n\r\nnetstat -bano | grep LISTENING\r\n\r\nnetstat -bano | findstr \/R \/C:\"[LISTING]\"\r\n<\/pre>\n
\u65b9\u5f0f 3\uff1anmap \u547d\u4ee4<\/strong><\/div>\n

\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n

$ sudo nmap -sT -O localhost\r\n\r\n$ sudo nmap -sU -O 192.168.2.13 ### \u5217\u51fa\u6253\u5f00\u7684 UDP \u7aef\u53e3\r\n\r\n$ sudo nmap -sT -O 192.168.2.13 ### \u5217\u51fa\u6253\u5f00\u7684 TCP \u7aef\u53e3\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\u5982\u4e0b\uff1a<\/p>\n

\"\"<\/p>\n

\u4f60\u53ef\u4ee5\u7528\u4e00\u53e5\u547d\u4ee4\u5408\u5e76 TCP\/UDP \u626b\u63cf\uff1a<\/p>\n

$ sudo nmap -sTU -O 192.168.2.13<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-8081-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/lsof-netstat-nmap-port.html<\/a>\u7f16\u8f91\uff1a\u9676\u6b66\u6770\uff0c\u5ba1\u6838\u5458\uff1a\u82cf\u897f\u4e91<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u9a8c\u8bc1\u54ea\u4e9b\u7aef\u53e3\u5728\u670d\u52a1\u5668\u7684\u7f51\u7edc\u63a5\u53e3\u4e0a\u5904\u4e8e\u76d1\u542c\u72b6\u6001\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u901a\u8fc7\u5f00\u653e\u7aef\u53e3\u7684\u72b6\u6001\u53ef\u4ee5\u68c0\u6d4b\u7f51\u7edc\u5165\u4fb5\u3001\u6392\u9664\u6545\u969c\u3001 […]<\/p>\n","protected":false},"author":63,"featured_media":45813,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-45796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/45796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=45796"}],"version-history":[{"count":18,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/45796\/revisions"}],"predecessor-version":[{"id":269397,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/45796\/revisions\/269397"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/45813"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=45796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=45796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=45796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}