Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Test-TcpPortConnection {
- param($hostname,$port)
- try {
- $tcp = New-Object System.Net.Sockets.TcpClient($hostname,$port)
- $tcp.Close()
- return $true;
- }
- catch {
- return $false;
- }
- }
- // Returns True unless your network is messed up
- Test-TcpPortConnection "www.google.com" 80
- // Returns False unless your dns resolves this
- Test-TcpPortConnection "www.thisisnotarealhost.com" 80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement