首页 > 系统相关 >使用Power Shell/PortQuery检查打开(侦听)端口

使用Power Shell/PortQuery检查打开(侦听)端口

时间:2023-07-06 16:31:57浏览次数:45  
标签:Shell name Power portqry TCP NetConnection query PortQuery port

你可以使用Test-NetConnection 检查远程计算机上的端口是否可用(打开)。您可以使用它检查远程服务器或网络服务的响应和可用性,测试TCP端口是否被防火墙阻止,检查ICMP可用性和路由。事实上,Test-NetConnection取代了一些流行的网络管理工具,如ping、tracert、telnet、pathping、TCP端口扫描程序等。

1.检查打开的TCP端口:

Test-NetConnection -ComputerName Exch01 -Port 25

检查远程邮件服务器上的TCP端口25(SMTP协议)是否打开.

Test-NetConnection别名为TNC

TNC exch01 -Port 25

不带参数的TNC,默认检查internetbeacon.mssedge.net主机的可用性:

使用Power Shell/PortQuery检查打开(侦听)端口_PortQuery


可以添加 –InformationLevel Detailed 显示更详细的信息:

TNC 192.168.66.10 -Port 3389 -InformationLevel Detailed

使用Power Shell/PortQuery检查打开(侦听)端口_ports_02

可以使用–CommonTCPPort 来指定网络协议的名称:如 http,smb,rdp,winrm

Test-NetConnection -ComputerName baidu.com -CommonTCPPort HTTP

使用Power Shell/PortQuery检查打开(侦听)端口_Test-NetConnection_03

Test-NetConnection rds01 –CommonTCPPort RDP

Test-NetConnection 192.168.66.10 -port 445|Format-List *

使用Power Shell/PortQuery检查打开(侦听)端口_ports_04

TNC 192.168.66.10 -Port 3389 -InformationLevel Quiet

使用Power Shell/PortQuery检查打开(侦听)端口_TCP_05

可以添加–TraceRoute 来跟踪路由,也可以用-Hops参数来限制跳数:

Test-NetConnection baidu.com –TraceRoute

使用Power Shell/PortQuery检查打开(侦听)端口_TCP_06

检查多个主机上的打开端口: 

Get-Content c:\PS\list_servers.txt |  where { -NOT (Test-Netconnection $_ -Port 22  -InformationLevel Quiet)}| Format-Table -AutoSize

foreach ($ip in 10..50) {Test-NetConnection -Port 3389 -InformationLevel "Detailed" 192.168.66.$ip}

foreach ($port in 1..1024) {If (($a=Test-NetConnection dc01 -Port $port -WarningAction SilentlyContinue).tcpTestSucceeded -eq $true){ "TCP port $port is open!"}}

How to List Open Ports on Windows with PowerShell:

Get-NetTcpConnection -State Listen | Select-Object LocalAddress,LocalPort| Sort-Object -Property LocalPort | Format-Table

使用Power Shell/PortQuery检查打开(侦听)端口_TCP_07


Get-Process -Id (Get-NetTCPConnection -LocalPort 22).OwningProcess | ft Id, ProcessName, UserName, Path

使用Power Shell/PortQuery检查打开(侦听)端口_UDP_08


Using PortQry to Check TCP/UDP Open Ports (Port Scanner):

下载 PortQryV2:

https://www.microsoft.com/en-us/download/details.aspx?id=17148

下载PortQryUI:

http://download.microsoft.com/download/3/f/4/3f4c6a54-65f0-4164-bdec-a3411ba24d3a/PortQryUI.exe

PortQry -n server [-p protocol] [-e || -r || -o endpoint(s)]

  • -n is the name or IP address of the server, which availability you are checking;
  • -e is the port number to be checked (from 1 to 65535);
  • -r is the range of ports to be checked (for example, 1:80);
  • -p is the protocol used for checking. It may be TCP, UDP, or BOTH (TCP is used by default).


PS D:\PortQryUI> .\PortQry.exe help


PortQry version 2.0


Displays the state of TCP and UDP ports



Command line mode:  portqry -n name_to_query [-options]

Interactive mode:   portqry -i [-n name_to_query] [-options]

Local Mode:         portqry -local | -wpid pid| -wport port [-options]


Command line mode:


portqry -n name_to_query [-p protocol] [-e || -r || -o endpoint(s)] [-q]

       [-l logfile] [-sp source_port] [-sl] [-cn SNMP community name]


Command line mode options explained:

       -n [name_to_query] IP address or name of system to query

       -p [protocol] TCP or UDP or BOTH (default is TCP)

       -e [endpoint] port number and/or port ranges seperated by commas

           to query. For port range, the end port should be equal or greater than

           the start port. Valid port should be in range 1-65535.

           For example: 80,53,1024-1350.

       -r [end point range] range of ports to query (start:end)

       -o [end point order] range of ports to query in an order (x,y,z)

       -l [logfile] name of text log file to create

       -y overwrites existing text log file without prompting

       -sp [source port] initial source port to use for query

       -sl 'slow link delay' waits longer for UDP replies from remote systems

       -nr by-passes default IP address-to-name resolution

           ignored unless an IP address is specified after -n

       -cn specifies SNMP community name for query

           ignored unless querying an SNMP port

           must be delimited with !

       -q 'quiet' operation runs with no output

          returns 0 if port is listening

          returns 1 if port is not listening

          returns 2 if port is listening or filtered


Notes:  PortQry runs on Windows 2000 and later systems

       Defaults: TCP, port 80, no log file, slow link delay off

       Hit Ctrl-c to terminate prematurely


examples:

portqry -n myserver.com -e 25

portqry -n 10.0.0.1 -e 53 -p UDP -i

portqry -n host1.dev.reskit.com -r 21:445

portqry -n 10.0.0.1 -o 25,445,1024 -p both -sp 53

portqry -n host2 -cn !my community name! -e 161 -p udp



Interactive Mode:


Used as an alternative to command line mode


portqry -i [-options]


For help with Interactive mode options:

       - run portqry.exe

       - then type 'help' <enter>


example:

portqry -i -n server1 -e 135 -p both



Local Mode:


Local Mode used to get detailed data on local system's ports


portqry -local | -wpid pid | -wport port [-wt seconds] [-l logfile] [-v]


Local mode options explained:

       -local enumerates local port usage, port to process mapping,

              service port usage, and lists loaded modules


       -wport [port_number] watches specified port

              reports when port's connection status changes


       -wpid [process_ID] watches specified process ID (PID)

             reports when PID's connection status changes


       -wt [seconds] watch time option

           specifies how often to check for status changes

           valid range: 1 - 1200 seconds

           default value is 60 seconds


       -l [logfile] name of text log file to create

       -v requests verbose output


Notes:  PortQry runs on Windows 2000 and later systems

       For best results run in context of local administrator

       Port to process mapping may not be available on all systems

       Hit Ctrl-c to terminate prematurely


examples:

portqry -local

portqry -local -l logfile.txt -v

portqry -wpid 1272 -wt 5 -l logfile.txt -y -v

portqry -wport 53 -l dnslog.txt

PortQueryUI

使用Power Shell/PortQuery检查打开(侦听)端口_ports_09

Possible return codes in PortQueryUI (highlighted in the screenshot):


0 (0x00000000) – the connection has been established successfully and the port is available;

1 (0x00000001) – the specified port is unavailable or filtered;

2 (0x00000002 – a normal return code when checking the availability of a UDP connection, since ACK response is not returned.

标签:Shell,name,Power,portqry,TCP,NetConnection,query,PortQuery,port
From: https://blog.51cto.com/ganzy/6643506

相关文章

  • PowerShell系列九:文档和测试
    文档functionAdd-Access{<#.SYNOPSIS文件和目录添加访问权限.DESCRIPTIONIcacls的包装,能够对目录和文件添加三种权限。读取,修改,完全控制.PARAMETERPath需要添加权限的{文件|目录}.PARAMETERUser授予访问......
  • PowerDesigner反向导入表+PowerDesigner的ER图设计+PowerDesigner连接外键的线(版本16.
    使用PowerDesigner导入表+PowerDesigner画ER图+PowerDesigner设置外键ps:①ER图:就是PD中的PhysicalDiagram一、导入表,并设置备注为PD中的显示名称参考:https://blog.csdn.net/weixin_37530941/article/details/107331105利用建表语句sql导入表1、新建数据库模型2......
  • 1.7 完善自定位ShellCode后门
    在之前的文章中,我们实现了一个正向的匿名管道ShellCode后门,为了保证文章的简洁易懂并没有增加针对调用函数的动态定位功能,此类方法在更换系统后则由于地址变化导致我们的后门无法正常使用,接下来将实现通过PEB获取GetProcAddrees函数地址,并根据该函数实现所需其他函数的地址自定位......
  • PowerBuilder从入坑到放弃(二)编码规范
    前言上一篇我们从0到1用pb开发了一个helloworld程序,并成功将开发的程序编译打包并且制作了安装包。程序员最讨厌的莫过于写文档和别人不写注释。不知道大家会不会和我一样,在找bug时,有段代码,心中不知默默的骂了它多少遍。哪个sx写的这代码,研究了一段时间发现,原来那sx竟是自己......
  • powershell profile
    functionwelcome{echo"________|||||||||/_|||||_____|||________......
  • shell脚本:将运行容器的日志输出到文件清理服务器上的符合条件的docker镜像
    采集容器日志的shell脚本内容为:点击查看代码#!/bin/bashexportLANG=zh_CN.gb18030.~/.bash_profile#日志放置目录log_path=/aa/bb/cc/dd/eetodaydate=$(date+%Y%m%d)nowdate=$(date+%Y%m%d%H%M)#pod列表dube_pod_id='xx1-servicexx2-servicexx3-servicexx4-se......
  • shell脚本:对开发入库的sql脚本进行检查
    shell脚本内容为:点击查看代码#!/bin/bashexportLANG=en_US.UTF-8exportNLS_LANG="AMERICAN_AMERICA.AL32UTF8"source/etc/profilesource/root/.bash_profileHOME=$(cd$(dirname$0);pwd)DOC_HOME=${HOME}/releasedocDOC_SVN_PATH=http://192.168.xx.xx/bushi......
  • 如何正确格式化sqlite shell输出?
    sqlite>.modecolumnsqlite>select*fromfoo;234kshitizdba.sesqlite>.headersonsqlite>select*fromfoo;barbazbaf------------------------------234kshitizdba.seecho-e'.modecolum......
  • PowerShell系列四:容器操作
    容器容器是一个很通用的概念。比如文件、文件夹、注册表、磁盘分区、数组、hash表、命名空间、用户组、OU、数据库、数据表等等,它们的共同点就是包含了数据。在PowerShell中一切都是从"PSDrive"开始的,您熟悉了操作PSDrive,基本就涵盖了对资源的操作。Get-PSDrive#输出Name......
  • 1.6 编写双管道ShellCode后门
    本文将介绍如何将CMD绑定到双向管道上,这是一种常用的黑客反弹技巧,可以让用户在命令行界面下与其他程序进行交互,我们将从创建管道、启动进程、传输数据等方面对这个功能进行详细讲解。此外,本文还将通过使用汇编语言一步步来实现这个可被注入的ShellCode后门,并以此提高代码通用性。......