cports:带有命令行(cmd)模式的网络连接查看器

cports

cports是国外友人开发的一款连接查看器,功能非常齐全,最重要的是可以使用外部调用获取连接信息 甚至可以调用 关闭连接

软件官方网站地址:http://www.nirsoft.net/utils/cports.html

Command-Line Options

/stext <Filename> Save the list of all opened TCP/UDP ports into a regular text file.
/stab <Filename> Save the list of all opened TCP/UDP ports into a tab-delimited text file.
/scomma <Filename> Save the list of all opened TCP/UDP ports into a comma-delimited text file.
/stabular <Filename> Save the list of all opened TCP/UDP ports into a tabular text file.
/shtml <Filename> Save the list of all opened TCP/UDP ports into HTML file (Horizontal).
/sverhtml <Filename> Save the list of all opened TCP/UDP ports into HTML file (Vertical).
/sxml <Filename> Save the list of all opened TCP/UDP ports to XML file.
/sort <column> This command-line option can be used with other save options for sorting by the desired column. If you don’t specify this option, the list is sorted according to the last sort that you made from the user interface. The <column> parameter can specify the column index (0 for the first column, 1 for the second column, and so on) or the name of the column, like “Remote Port” and “Remote Address”. You can specify the ‘~’ prefix character (e.g: “~Remote Address”) if you want to sort in descending order. You can put multiple /sort in the command-line if you want to sort by multiple columns.Examples:
cports.exe /shtml “f:\temp\1.html” /sort 2 /sort ~1
cports.exe /shtml “f:\temp\1.html” /sort “Protocol” /sort “~Remote Address”
/nosort When you specify this command-line option, the list will be saved without any sorting.
/filter <filter string> Start CurrPorts with the specified filters. If you want to specify more than one filter, use the ‘;’ character as a delimiter.
/cfg <cfg filename> Start CurrPorts with the specified config file.
/MarkPorts
/DisplayUdpPorts
/DisplayTcpPorts
/DisplayClosedPorts
/MarkNewModifiedPorts
/SortOnAutoRefresh
/AlwaysOnTop
/AskBefore
/DisplayIPv6Ports
/DisplayListening
/DisplayEstablished
/DisplayNoState
/DisplayNoRemoteIP
/ResolveAddresses
/RememberLastFilter
/DisplayPortInAddress
/AutoRefresh,
/ShowInfoTip
/TrayIcon
/TrayIconOneClick
/StartAsHidden
/LogChanges
/LogFilename
/DisabledFilters
/AddExportHeaderLine
You can use all these parameters to control the options that are available under the Options and View menus.
For example, if you want to start CurrPorts with ‘Display UDP Ports’ turned off and ‘Display Closed’ turned on:
cports.exe /DisplayUdpPorts 0 /DisplayClosedPorts 1You can also use these parameters in conjunction with all save parameters. For example: If you want to save into tab-delimited file only the UDP ports:
cports.exe /DisplayUdpPorts 1 /DisplayTcpPorts 0 /stab “c:\temp\udp.txt”

 

Here’s some examples:

  • Save all opened TCP/IP ports created by Internet Explorer browser to HTML file:
    cports.exe /filter “include:process:iexplore” /shtml “c:\temp\ports.html”
  • Add all opened ports information to ports.txt (as tab-delimited text file). This example only works when running it from a command-prompt window.
    cports.exe /stab “” >> c:\temp\cports1.txt
  • Start CurrPorts with filter that will only display the opened ports of Internet Explorer and FireFox:
    cports.exe /filter “include:process:firefox;include:process:iexplore”

 

Closing a Connection From Command-Line

Starting from version 1.09, you can close one or more connections from command-line, by using /close parameter.
The syntax of /close command:
/close <Local Address> <Local Port> <Remote Address> <Remote Port> {Process Name}

For each parameter, you can specify “*” in order to include all ports or addresses. The process name is an optional parameter. If you specify a process, only the ports of the specified process will be closed.
Examples:

  • Close all connections with remote port 80 and remote address 192.168.1.10:
    /close * * 192.168.1.10 80
  • Close all connections with remote port 80 (for all remote addresses):
    /close * * * 80
  • Close all connections to remote address 192.168.20.30:
    /close * * 192.168.20.30 *
  • Close all connections with local port 80:
    /close * 80 * *
  • Close all connections of Firefox with remote port 80:
    /close * * * 80 firefox.exe

有关于如何调用帮助文件内也记录得非常清楚

比如,生成一份连接信息表调用:cports.exe /stab data.txt

强制关闭连接:cports.exe /close 本地地址(*代表全部) 本地端口(*代表全部) 远程地址(*代表全部) 远程端口(*代表全部) 进程名(可选)

 

原创文章,转载请注明: 转载自YXZ’s Blog

本文链接地址: cports:带有命令行(cmd)模式的网络连接查看器