Настройки сети
Список командлетов работы с сетевыми настройками
get-command -module NetTCPIP
Сетевые адаптеры
Get-NetAdapter Get-NetAdapter –IncludeHidden Get-NetAdapter -Physical | ? {$_.Status -eq "Up"} Get-NetAdapter -Name Ethernet0 Get-NetAdapter -InterfaceIndex 8 Get-NetAdapter |Select-Object name,LinkSpeed,InterfaceOperationalStatus,MacAddress Rename-NetAdapter -Name Ethernet0 -NewName LAN Get-NetAdapter -InterfaceIndex 13| Disable-NetAdapter Enable-NetAdapter -InterfaceDescription “Hyper-V Virtual Ethernet Adapter" Get-NetAdapter | ft Name, Status, Linkspeed, VlanID Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName Get-NetAdapterHardwareInfo #Информация о физических параметров подключения сетевых адаптерах (PCI слот, шина и т.д.).
Текущие настройки сети
Get-NetIPConfiguration -InterfaceAlias Ethernet0 Get-NetIPConfiguration -InterfaceAlias Ethernet0 -Detailed Get-NetIPAddress -AddressFamily ipv4|ft (Get-NetAdapter -Name ethernet0 | Get-NetIPAddress).IPv4Address Get-NetTCPSetting Set-NetTCPSetting -SettingName DatacenterCustom,Datacenter -CongestionProvider DCTCP Set-NetTCPSetting -SettingName DatacenterCustom,Datacenter -CwndRestart True Set-NetTCPSetting -SettingName DatacenterCustom,Datacenter -ForceWS Disabled Get-NetAdapterBinding -Name ethernet -IncludeHidden -AllBindings Get-NetAdapter -Name Ethernet0| New-NetIPAddress –IPAddress 192.168.1.80 -DefaultGateway 192.168.1.1 -PrefixLength 24 $NetAlias=Get-NetIPInterface -AddressFamily IPv4 | Get-NetIPInterface -AddressFamily IPv4 |?{($_.InterfaceAlias -notmatch "Loopback|VMwa") -and ($_.ConnectionState -eq 'Connected')} | select -expand interfacealias $i = Get-NetIPConfiguration -InterfaceAlias $NetAlias -Detailed $c = 'MyComputer' $result=@() $result += New-Object -TypeName PSCustomObject -Property ( [ordered]@{ 'Server' = $c 'Interface' = $i.InterfaceAlias -join ',' 'IPv4Address' = $i.Ipv4Address -join ',' 'Gateway ' = $i.IPv4DefaultGateway | select -expand nexthop 'DNSServer' = ($i.DNSServer | Select-Object -ExpandProperty ServerAddresses) -join ',' }) $result
Текущие соединения
get-nettcpconnection | select local*,remote*,state,@{Name="Process";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}},@{Name="Path";Expression={(Get-Process -Id $_.OwningProcess).Path}}
или
$CurIP= (Get-NetIPConfiguration).IPv4Address.IPv4Address $MyConn=get-nettcpconnection | select local*,remote*,@{Name="PTR";Expression={([System.Net.Dns]::GetHostbyAddress($_.RemoteAddress)).hostname}},state,` @{Name="Process";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} | where-object{ $_.LocalAddress -notmatch "::|0.0.0.0|127.0.0.1" ` -and $_.state -match "Listen|Established" ` -and $_.RemoteAddress -notmatch "::|0.0.0.0|127.0.0.1|$CurIP" } $MyConn| Out-GridView
DNS
[system.net.dns]::GetHostByName("www.ru")
Whois
Получить информацию по IP адресу
Invoke-RestMethod -Uri "http://ipwho.is/213.108.173.146"
$myIPList=@() $MyIP=@' 213.108.173.146 13.25.11.136 '@.split("",[System.StringSplitOptions]::RemoveEmptyEntries) foreach ($MyItem in $MyIP){ $myTest = Invoke-RestMethod -Uri "http://ipwho.is/$MyItem" | select ip,country,region,city,postal,capital, @{name="ASN";e={$_.connection.asn}}, @{name="ISP";e={$_.connection.isp}}, @{name="ORG";e={$_.connection.org}}, @{name="Domain";e={$_.connection.domain}} $myIPList+=$MyTest } $myIPList | ft -a
IP адрес
Преобразование IP адреса к реверсному
"192.168.1.1" -replace '(\d+)\.(\d+)\.(\d+)\.(\d+)', '$4.$3.$2.$1' ("192.168.1.1" -split '\.')[-1..-4]-join'.'
Сортировка IP адресов
"192.168.1.10","10.10.10.1","50.50.50.50" | Sort-Object -Property { [System.Version]$_} "192.168.1.10","10.10.10.1","50.50.50.50" | Sort-Object -Property { $_ -as [Version] } "192.168.1.10","10.10.10.1","50.50.50.50" | Sort-Object { [regex]::Replace( $_, '\d+', { $args.Value.PadLeft(3, '0') } )}
Валидация IP адреса
[bool]("192.168.1.10" -as [ipaddress])
TLS
Quick ProTip: Negotiate TLS Connections In Powershell With A Minimum TLS Version Requirement
1. Проверить текущие настройки поддерживаемых протоколов
[Net.ServicePointManager]::SecurityProtocol
Возможные варианты
[enum]::GetNames([Net.SecurityProtocolType]) [System.Net.ServicePointManager]::SecurityProtocol = 'Tls11, Tls12'
В моей системе Windows 10 с Powershell v5.1 это значение возвращает значение SystemDefault. Это значение было введено в .NET 4.7 (предыдущие версии .NET не возвращают значения по умолчанию, только перечисляемый список) и позволяет вашей операционной системе выбирать протокол, с которым лучше всего согласовывать соединение. При обычных обстоятельствах это лучший вариант для использования, поскольку значения по умолчанию меняются в зависимости от текущей ситуации с безопасностью.
Однако SystemDefault может быть слишком мягким в объявлении доступных протоколов. SSLv3?! - Да, нет, спасибо.
Мы видим, что по умолчанию
Set strong cryptography on 64 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
set strong cryptography on 32 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
3. Перезапустить Powershell и проверить настройки поддерживаемых протоколов [Net.ServicePointManager]::SecurityProtocol
Open Powershell (As Admin)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PING
$Computers = @( "10.0.10.10", "10.0.10.11", "10.0.10.12" ) $Timeout = 3000 $Ping = New-Object System.Net.NetworkInformation.Ping $Results = Foreach ($Computer in $Computers) { $Response = $Ping.Send($Computer,$Timeout) [PSCustomObject]@{ TimeStamp = Get-Date Address = $Computer Status = $Response.Status RTT = $Response.RoundtripTime } } <# Here's examples of what the results would look like if you wanted to do anything with that info TimeStamp Address Status RTT --------- ------- ------ --- 9/26/2024 9:40:48 AM 10.0.10.10 Success 26 9/26/2024 9:40:48 AM 10.0.10.11 Success 36 9/26/2024 9:40:48 AM 10.0.10.12 Success 25 9/26/2024 9:40:48 AM 10.0.10.13 Success 18 9/26/2024 9:40:51 AM 10.0.10.14 TimedOut 0 #> $OK = 1 Foreach ($Result in $Results) { If ($Result.Status -ne "Success") { Write-Output "$($Result.Address) NOK" $OK = 0 } } If ($OK -eq 1) { Write-Output "Everything is OK" }