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

Find the connection status through the Socket file descriptor in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the relevant knowledge of "finding connection status through Socket file descriptors in Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

There are many numeric named subdirectories under the Proc virtual file system, which represent the process number that the system is currently running

The / proc/N/fd directory holds the open file descriptor, which points to a link to the actual file. As follows:

The code is as follows:

[root@XXXXXXX_10_1_17_138 song_test] # ll / proc/25465/fd

Total 0

Lrwx- 1 root root 64 Apr 14 09:36 0-> / dev/pts/4 (deleted)

Lrwx- 1 root root 64 Apr 14 09:36 1-> / dev/pts/4 (deleted)

Lrwx- 1 root root 64 Apr 14 09:36 10-> socket: [2289128790]

Lrwx- 1 root root 64 Apr 14 09:36-> socket: [2305227922]

Lrwx- 1 root root 64 Apr 14 09:36 101-> socket: [2305224138]

Lrwx- 1 root root 64 Apr 14 09:36 102-> socket: [2305233625]

Lrwx- 1 root root 64 Apr 14 09:36 103-> socket: [2305215571]

Lrwx- 1 root root 64 Apr 14 09:36 104-> socket: [2305243589]

Lrwx- 1 root root 64 Apr 14 09:36 105-> socket: [2305394065]

Lrwx- 1 root root 64 Apr 14 09:36 106-> socket: [2305394002]

What should we do if we want to check the link status of the 101Socket file descriptor? The smart one noticed that there was a number [2305224138] behind it. Where did this number come from? Spectators, please look down.

The status information of all TCP links is saved in the / proc/net/tcp directory.

The code is as follows:

[root@XXXXXXX_10_1_17_138 song_test] # cat / proc/net/tcp

Sl local_address rem_address st tx_queue rx_queue tr tm- > when retrnsmt uid timeout inode

0: 8A11010A:7DC8 000000000A 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

1: 8A11010A:0369 000000000A 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

51: 8A11010A:FAF4 9C01010A:0CEA 06 00000000:00000000 03:00000938 00000000 000 2 ffff8810516c01c0

52: 8A11010A:21CD 0964010A:2227 01 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

53: 8A11010A:FB8A 9C01010A:0CEA 06 00000000:00000000 03:000012A8 00000000 000 2 ffff8810516c04c0

54: 8A11010A:73E5 4511010A:0050 06 00000000:00000000 03:00000EA8 00000000 000 2 ffff88106898a880

55: 8A11010A:89AD F300010A:1F90 08 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

187: 8A11010A:0ACB 8811010A:1F90 06 00000000:00000000 03:0000028E 00000000 0002 ffff881050e9ccc0

188: 8A11010A:FB6C 9C01010A:0CEA 06 00000000:00000000 03:000010CB 00000000 000 2 ffff88104fd8dd80

It looks like the number [2305224138]. This is where it comes from. Here we can find the linked IP, PORT link quad [8A11010A:21CD 0964010A:2227]. This place is saved in hexadecimal, converted to decimal [10.1.17.138VO8653 10.1.100.9Va8743].

Take a look at the network connection status:

The code is as follows:

[root@XXXXXXX_10_1_17_138 song_test] # netstat-ntp

Active Internet connections (w _ servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

Tcp 0 0 10.1.17.138 TIME_WAIT-64428 10.1.156 TIME_WAIT-

Tcp 0 0 10.1.17.138 64244 10.1.1.156 3306-

Tcp 0 166 10.1.17.138:8653 10.1.100.9:8743 ESTABLISHED 25465/./index_searc

Tcp 0 0 10.1.17.138 TIME_WAIT-64394 10.1.156 TIME_WAIT-

Tcp 0 0 10.1.17.138 TIME_WAIT 29669 10.1.17.69 TIME_WAIT-

Tcp 0 0 10.1.17.138 tcp 46336 10.1.17.68 80 TIME_WAIT-

Tcp 0 0:: ffff:10.1.17.138:8080:: ffff:10.1.17.136:27247 TIME_WAIT-

Back to the beginning: the 101 Socket file descriptor represents a TCP connection from the local [10.1.17.138VO8653] to [10.1.100.9V8743]!

This is the end of "finding connection status through Socket file descriptors in Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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