In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to check port occupancy under Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. Lsof-I: the port number is used to view the occupancy of a port, for example, to check the usage of port 8000, and lsof-i 8000.
# lsof-iroot 8000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME lwfs 22065 root 6u IPv4 4395053 0t0 TCP *: irdmi (LISTEN) you can see that port 8000 has been occupied by the lightweight file system forwarding service lwfs
2. Netstat-tunlp | grep port number, which is used to view the progress of the specified port number. For example, for port 8000, netstat-tunlp | grep 8000
# netstat-tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0 0 only servers 111 0.0.0 0 LISTEN 4814/rpcbind tcp 0 0 0.0.0 0 0.0.0.0 * LISTEN 25492/qemu-kvm tcp 0 00.0.0.0vel6996 0.0.0.0 LISTEN 22065/lwfs tcp 0 192.168.122.1 Vol 53 0.0.0.0Vol * LISTEN 38296/dnsmasq tcp 0 0 0.0.0.0 LISTEN 5013/cupsd tcp 22 0.0.0.0 LISTEN 5013/cupsd tcp * LISTEN 5278/sshd tcp 0 0 127.0.1 0 0127.0.0.1 LISTEN 5962/master tcp 25 0.0.0.0 LISTEN 44868/lwfs tcp 0 0 0.0.0.0 LISTEN 44868/lwfs tcp 0 0 0.0.0.0: 8000 0.0.0.0 tcp * LISTEN 22065/lwfs # netstat-tunlp | grep 8000 tcp 00 0.0.0.0 tunlp 8000 0.0.0.0 tcp * explain the meaning of several parameters:
-t (tcp) shows only tcp related options-u (udp) shows only udp related options-n refuses to show aliases Can display all the numbers converted to numbers-l only lists the service status in Listen (monitoring)-p shows the name of the program that establishes the relevant link and appends a python port occupation monitoring program, which can monitor whether the port of the specified IP is occupied.
1 #! / usr/bin/env python 2 #-*-coding:utf-8-*-3 4 import socket, time, thread 5 socket.setdefaulttimeout (3) # set default timeout 6 7 def socket_port (ip, port): 8 "" 9 enter IP and port number Scan to determine whether the port is occupied by 10 "" 11 try: 12 if port > = 65535: 13 print u' Port scan ends'14 s=socket.socket (socket.AF_INET, socket.SOCK_STREAM) 15 result=s.connect_ex ((ip, port)) 16 if result==0: 17 lock.acquire () 18 print ip,u':',port U' Port occupied'19 lock.release () 20 except: 21 print U' Port scan abnormal'22 23 def ip_scan (ip): 24 "" 25 input IP Scan IP 0-65534 port case 26 "27 try: 28 print u' start scanning% s'% ip 29 start_time=time.time () 30 for i in range (0meme 65534): 31 thread.start_new_thread (socket_port, (ip, int (I)) 32 print u' scan port complete Total time:% .2f'% (time.time ()-start_time) 33 # raw_input ("Press Enter to Exit") 34 except: 35 print u' scan ip error'36 37 if _ name__=='__main__': 38 url=raw_input ('Input the ip you want to scan:') 39 lock=thread.allocate_lock () 40 ip_scan (url) the execution result of this program is as follows:
# python scan_port.py Input the ip you want to scan: 20.0.208.112 start scanning 20.0.208.112 20.0.208.112: 111Port occupied 20.0.208.112: 22 Port occupied 20.0.208.112: 8000 Port occupied 20.0.208.112: 15996 Port occupied 20.0.208.112: 41734 Port occupied scanning Port completed Total time: 9.38 on "how to check port occupancy under Linux" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.