# Networking with Powershell ## Test-Connection Similar to ping ```powershell Test-Connection udemy.com # Multiple Connexion Test-Connection -ComputerName 8.8.8.8, 8.8.4.4 # Add Delay between ping attempt Test-Connection -ComputerName 8.8.8.8, 8.8.4.4 -Delay 5 # Number of ping attempts Test-Connection -ComputerName 8.8.8.8, 8.8.4.4 -Delay 5 - Count 2 ``` ## Test-NetConnection similar to test net-Connections but better output ```powershell Test-NetConnection udemy.com Test-NetConnection udemy.com -InfomationLevel "Detailed" #Populate a variable $test = Test-NetConnection udemy.com -InfomationLevel "Detailed" $test.PingReplyDetailed ``` ### TraceRoute ```powershell $test = Test-NetConnection udemy.com -TraceRoute # Limit traceroute to 3 hops $test = Test-NetConnection udemy.com -TraceRoute -Hops 3 ``` ### Portscan ```powershell Test-NetConnection wikipedia.org -CommonTCPPort "http" Test-NetConnection wikipedia.org -Port 80 Test-NetConnection wikipedia.org -Port 21 $ports = 22,80 $ports | forEach-Object {$port = $PSItem; if(Test-NetConnection udemy.com -Port $port -InformationLevel Quiet -WarningAction SilentlyContinue){Write-Host "Hey, $port is open !"} else { Write-Host "Hey, $port is closed ! "}} ``` ## Get-NetAdapter To see the network adapter of the machine ```powershell Get-NetAdapter #nicer view Get-NetAdapter | Format-List $netAdapter = Get-NetAdapter $netAdapter.MacAddress ``` ## Get-NetIPConfiguration To access ip address of the machine ```powershell Get-NetIPConfiguration $ipinfo = Get-NetIPConfiguration $ipinfo[0].IPv4Address ``` ## Resolve-DnsName ```powershell Resolve-DnsName udemy.com Resolve-DnsName udemy.com | Format-List ``` ## Get-DnsClientServerAddress ```powershell Get-DnsClientServerAddress -InterfaceAlias Ethernet $dnsserv = Get-DnsClientServerAddress -InterfaceAlias Ethernet $dnserv[0].ServerAddresses ``` ## Clear-DnsClientCache The **Clear-DnsClientCache** cmdlet clears the local DNS resolver cache on a Windows system. This forces the computer to request fresh DNS information from its configured DNS servers, which is useful for troubleshooting name resolution issues or testing DNS changes. The cmdlet requires administrative privileges and only affects the local machine. ```powershell Clear-DnsClientCache ```