LabVIEW基于Netstat列出活动的网络连接
该VI使用命令行“netstat”查询网络堆栈中的活动网络连接。除了连接状态之外,还会返回活动的本地和外部 IP 地址和端口号。
连接状态:Netstat 返回每个网络连接的状态,如下表所示。
State |
Description |
LISTEN |
accepting connections |
connection up and passing data |
程序截图如下所示。
更多的介绍,参见如下介绍,原文: http://linux-ip.net/html/tools-netstat.html
G.4. netstat
The netstat utility summarizes avariety of characteristics of the networking stack. With netstat you can learn a numberof important things. If no other type of data is requested it will report onthe state of all active sockets. You can however request the routingtable, masquerading table, network interface statistics, and networkstack statistics [60].
G.4.1. Displaying socket status with netstat
One of the most common uses ofthe netstat utilityis to determine the state of sockets on a machine. There are many questionsthat netstat cananswer with the right set of options. Here's a list of some of the thingsdifferent things we can learn.
· whichservices are listening on which sockets
· whatprocess (and controlling PID) is listening on a given socket
· whetherdata is waiting to be read on a socket
· whatconnections are currently established to which sockets
Byinvoking netstat withoutany options, you are asking for a list of all currently open connections to andfrom the networking stack on the local machine. This means IP networkconnections, unix domain sockets, IPX sockets and Appletalk sockets amongothers. Naturally, we'll skip over the non-IP sockets since this is about IPnetworking with linux.
Assumethe --inet switchin all cases below unless we are examining a particular higher layer protocol(e.g., TCP with the --tcp switch or UDP with --udp switch.
Aconvenient feature of netstat isits ability to differentiate between two different sorts of name lookup.Normally the -n specifies no name lookup, butthis is ambiguous when there are hostnames, port names, and user names.Fortunately, netstat offersthe following options to differentiate the different forms of lookup andsuppress only the [un-]desired lookup.
· --numeric-hosts
· --numeric-ports
· --numeric-users
Theoption -n (my favorite), suppress all hostname, port name andusername lookup, and is a synonym for --numeric. I'll reiterate that hostnames andDNS in particular can be confusing, or worse, misleading when trying todiagnose or debug a networking related issue, so it is wise to suppresshostname lookups in these sorts of situations.
In Example G.11,“Displaying IP socket status with netstat” we will look at netstat's numeric output and thenwe'll invoke the same command but suppress the host lookups. Though the outputis almost the same, a particular situation might call for one or the otherinvocation.
Example G.11. DisplayingIP socket status with netstat
[root@morgan]# netstat --inet -n
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 192 192.168.98.82:22 192.168.99.35:40991 ESTABLISHED
tcp 0 0 192.168.98.82:42929 192.168.100.17:993 ESTABLISHED
tcp 96 0 127.0.0.1:40863 127.0.0.1:6010 ESTABLISHED
tcp 0 0 127.0.0.1:6010 127.0.0.1:40863 ESTABLISHED
tcp 0 0 127.0.0.1:38502 127.0.0.1:6010 ESTABLISHED
tcp 0 0 127.0.0.1:6010 127.0.0.1:38502 ESTABLISHED
tcp 0 0 192.168.98.82:53733 209.10.26.51:80 SYN_SENT
tcp 0 0 192.168.98.82:44468 192.168.100.17:993 ESTABLISHED
tcp 0 0 192.168.98.82:44320 192.168.100.17:139 TIME_WAIT
[root@morgan]# netstat --inet --numeric-hosts
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.98.82:ssh 192.168.99.35:40991 ESTABLISHED
tcp 0 0 192.168.98.82:42929 192.168.100.17:imaps ESTABLISHED
tcp 0 0 127.0.0.1:40863 127.0.0.:x11-ssh-offset ESTABLISHED
tcp 0 0 127.0.0.:x11-ssh-offset 127.0.0.1:40863 ESTABLISHED
tcp 0 0 127.0.0.1:38502 127.0.0.:x11-ssh-offset ESTABLISHED
tcp 0 0 127.0.0.:x11-ssh-offset 127.0.0.1:38502 ESTABLISHED
tcp 0 0 192.168.98.82:53733 209.10.26.51:http SYN_SENT
tcp 0 0 192.168.98.82:44468 192.168.100.17:imaps ESTABLISHED
tcp 0 0 192.168.98.82:44320 192.168.100:netbios-ssn TIME_WAIT
LabVIEW基于Netstat列出活动的网络连接2:https://developer.aliyun.com/article/1505743