Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux's method of viewing Ports

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to view the port of Linux, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

How does Linux view ports

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-i:8000COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMElwfs 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 0 0 127.0.0.1 LISTEN 44868/lwfs tcp 25 0.0.0.0 LISTEN 5962/master tcp 00 0.0.0.015 8666 0.0.0.0 LISTEN 44868/lwfs tcp 00 0.0.0.0000 0.0.0.0 grep 8000tcp * LISTEN 22065/lwfs# netstat-tunlp | grep 8000tcp 00 0.0.0.0 grep 8000tcp 8000 0.0.0.0 LISTEN 22065/lwfs

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 lists only the service status in Listen (monitoring)-p displays the name of the program that establishes the relevant link

Attach a python port occupancy monitoring program, which can monitor whether the port of the specified IP is occupied.

#! / usr/bin/env python #-*-coding:utf-8-*-import socket, time, thread socket.setdefaulttimeout (3) # set the default timeout def socket_port (ip, port): "" enter IP and port number Scan to determine whether the port is occupied "" try: if port > = 65535: print u' port scan ends' s=socket.socket (socket.AF_INET, socket.SOCK_STREAM) result=s.connect_ex ((ip, port)) if result==0: lock.acquire () print ip,u':',port,u' port occupied 'lock.release () except: print u' port scan exception' def ip_scan (ip): "enter IP Scan the 0-65534 port of IP "" try: print u' start scanning% s'% ip start_time=time.time () for i in range (0meme 65534): thread.start_new_thread (socket_port, (ip, int (I)) print u' scan port completed Total time:% .2f'% (time.time ()-start_time) # raw_input ("Press Enter to Exit") except: print u' scan ip error'if _ name__=='__main__': url=raw_input ('Input the ip you want to scan:') lock=thread.allocate_lock () ip_scan (url)

The execution result of the program is as follows:

# python scan_port.pyInput the ip you want to scan: 20.0.208.112 start scanning 20.0.208.11220.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 and above are all the contents of Linux's method of viewing ports. Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report