Below is a T-SQL statement that lets you get information about the IP-address and TCP-port number for a Microsoft SQL-server.
SELECT CONNECTIONPROPERTY('local_net_address') AS IPAddress, CONNECTIONPROPERTY('local_tcp_port') AS PortNumber;
Below is a T-SQL statement that lets you get information about the IP-address and TCP-port number for a Microsoft SQL-server.
SELECT CONNECTIONPROPERTY('local_net_address') AS IPAddress, CONNECTIONPROPERTY('local_tcp_port') AS PortNumber;
The below script in PowerShell can scan a given range of ports for a specific server and will – if a port on the server is open – return the text: TCP port <PORT NUMBER) is open!
foreach ($port in <START PORT>..<END PORT>) {If (($a=Test-NetConnection <SERVER> -Port $port -WarningAction SilentlyContinue).tcpTestSucceeded -eq $true){ "TCP port $port is open!"}}
Example
foreach ($port in 3388..3390) {If (($a=Test-NetConnection MYSERVER -Port $port -WarningAction SilentlyContinue).tcpTestSucceeded -eq $true){ "TCP port $port is open!"}}
TCP port 3389 is open!
NB! I looks like there should be “something” answering in the other end of the port before you will receive a ‘TCP port XXXX is open!‘
In newer versions of Windows you are not able to use the Telnet-command to test a port. Don’t worry. In PowerShell v. 4 and onwards you can use the command below.
Test-NetConnection <host> -port <port>
Eg.
Test-NetConnection www.ryslander.com -port 80