Skip to main content


Showing posts with the label security

PowerShell check if port is open

PowerShell code snippet to check or test whether a port is open or closed on the IP Address specified.

$port_num= "2443" $IP_Add=""
$result = New-Object Net.Sockets.TcpClient $IP_Add, $port_num
if($result.Connected) { write-host "Port 443 is open." $result.close() } else { write-host "Attempt to connect failed, check firewall or other settings." } ==============================

If port 2443 is open in IP Address then PowerShell script will show "Port 443 is open."
If port 2443 is close the script will show "Attempt to connect failed, check firewall or other settings."
If the port is closed it could be that the firewall is not set to accept incoming connections for the particular port.
Do not set firewall settings to open any port if it is not necessary to do it.
If the service or application that is using the port is not operational anymore then close the port that was used by the app…

Netsh show firewall state

How to check Windows firewall advance security current state using command line?
Command line below will check whether the firewall state is on or off.

To check the firewall state via command line type:
   netsh advfirewall monitor show firewall
Command above will display the current firewall state.
If the state shows “ON” the firewall is working.

Sample output:
Domain Profile Settings: ---------------------------------------------------------------------- State                                                   ON Firewall Policy                                   BlockInbound,AllowOutbound LocalFirewallRules                            Enable LocalConSecRules                             Enable InboundUserNotification                   Enable RemoteManagement                          Disable UnicastResponseToMulticast            Enable
Logging: LogAllowedConnections                   Disable LogDroppedConnections                   Disable FileName                                        …