From 6946de008cc48da1decc191b44f5dd3d4d90b2af Mon Sep 17 00:00:00 2001 From: mrsh Date: Sat, 10 Jan 2026 00:29:55 +0100 Subject: [PATCH] need refactorization Networking with powershell --- 4.Networking/1.check_port.ps1 | 9 ++ 4.Networking/Networking with Powershell.md | 107 +++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 4.Networking/1.check_port.ps1 diff --git a/4.Networking/1.check_port.ps1 b/4.Networking/1.check_port.ps1 new file mode 100644 index 0000000..745571f --- /dev/null +++ b/4.Networking/1.check_port.ps1 @@ -0,0 +1,9 @@ +$ports = 22,80 +$ports | forEach-Object { + $port = $PSItem; + if(Test-NetConnection udemy.com -Port $port){ + Write-Host "Hey, $port is open !"} + else { + Write-Host "Hey, $port is closed ! "} +} + diff --git a/4.Networking/Networking with Powershell.md b/4.Networking/Networking with Powershell.md index 0709747..68daa73 100644 --- a/4.Networking/Networking with Powershell.md +++ b/4.Networking/Networking with Powershell.md @@ -1 +1,108 @@ # 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 +```