Useful Script for Networking Test on PowerShell
We often need to test the network to investigate the source of the problem and must use our laptops to investigate the problem. Many companies have some rules to get installed the program on their computer. We can download Nmap (free network scanner), but due to company policy, we may be unable to install the program. How do we test the network with the resources we have?
I will share a few useful scripts for testing the network from your computer.
1- Continuous Ping with Timestamp;
ping.exe -t 10.116.2.27 | ForEach {"{0} - {1}" -f (Get-Date),$_} > C:\Users\Desktop\ping_log.txt
2- Scan Network;
1..254 | ForEach-Object {Get-WmiObject Win32_PingStatus -Filter "Address='192.168.1.$_' and Timeout=100 and ResolveAddressNames='true' and StatusCode=0" | select ProtocolAddress*}
3- TCP Port Scan;
1..1024 | % {echo ((New-Object Net.Sockets.TcpClient).Connect("10.7.66.223",$_)) "Open port - $_"} 2>$null
4- UDP Port Scan; Maybe you can test the TCP port with the telnet command, but you can't check whether the UDP port is open with telnet. This will do the job.
53 | % {echo ((New-Object Net.Sockets.UdpClient).Connect("8.8.8.8",$_)) "Open port - $_"} 2>$null
5- Scan Some Ports;
443,22,80,23 | % {echo ((New-Object Net.Sockets.TcpClient).Connect("192.168.1.1",$_)) "Open port - $_"} 2>$null
6- Test Connection;
Check the tcp connetion the below command.
Standard Alieses for Test-NetConnection: tnc
Thanks for Reading.
I was thinking of starting to use PS instead of CMD on Windows. This is great! Maybe there is a way to make an alias for this commands, and then it will be shorter?