$socket = new-object Net.Sockets.TcpClient
$socket.Connect($IPAddress,$Port)
$socket.Connected
Just supply an IP Address and Port number and it will return true or false, based on if it was able to connect.
$socket = new-object Net.Sockets.TcpClient
$socket.Connect($IPAddress,$Port)
$socket.Connected
Test-NetConnection -Computer $Server -CommonTCPPort RDP
PS C:\> $Server = 'AD01' >> Test-NetConnection -Computer $Server -CommonTCPPort RDP ComputerName : DC01 RemoteAddress : 10.10.5.12 RemotePort : 3389 InterfaceAlias : vEthernet (External (NIC)) SourceAddress : 10.10.5.200 TcpTestSucceeded : True
Invoke-RestMethod 'https://api.ipify.org?format=json' | Select-Object -ExpandProperty IP
PS C:\> Invoke-RestMethod 'https://api.ipify.org?format=json' | Select-Object -ExpandProperty IP 72.30.35.10
[System.Net.Dns]::GetHostbyAddress($IPAddress)
PS C:\> $IPAddress = "8.8.8.8" >> [System.Net.Dns]::GetHostbyAddress($IPAddress) HostName Aliases AddressList -------- ------- ----------- google-public-dns-a.google.com {} {8.8.8.8}
[System.Net.Dns]::GetHostAddresses($ServerName)
PS C:\> $ServerName = 'DC01' >> [System.Net.Dns]::GetHostAddresses($ServerName) Address : 167840266 AddressFamily : InterNetwork ScopeId : IsIPv6Multicast : False IsIPv6LinkLocal : False IsIPv6SiteLocal : False IsIPv6Teredo : False IsIPv4MappedToIPv6 : False IPAddressToString : 10.10.1.10
Get-NetIPAddress
PS C:\> Get-NetIPAddress IPAddress : 10.10.1.10 InterfaceIndex : 12 InterfaceAlias : Ethernet AddressFamily : IPv4 Type : Unicast PrefixLength : 24 PrefixOrigin : Manual SuffixOrigin : Manual AddressState : Preferred ValidLifetime : Infinite ([TimeSpan]::MaxValue) PreferredLifetime : Infinite ([TimeSpan]::MaxValue) SkipAsSource : False PolicyStore : ActiveStore