-
Notifications
You must be signed in to change notification settings - Fork 4
/
testport.ps1
60 lines (58 loc) · 2.04 KB
/
testport.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function QuerySQLListner{
[cmdletbinding(
DefaultParameterSetName = '',
ConfirmImpact = "low"
)]
Param(
[Parameter(
Mandatory = $True,
Position = 0,
ParameterSetName = '',
ValueFromPipeline = $True)]
[string]$Computer
)
Begin {
$ErrorActionPreference = "SilentlyContinue"
$Port = 1434
$ConnectionTimeout = 1000
}
Process {
[System.Net.Dns]::GetHostEntry($Computer).AddressList[0].IPAddressToString
$FormattedResults = "" | Select ServerName, InstanceName, IsClustered, Version, TCP,NamedPipe
$UDPClient = new-Object system.Net.Sockets.Udpclient
$UDPClient.client.ReceiveTimeout = $ConnectionTimeout
$UDPClient.Connect("$Computer",$Port)
$ToASCII = new-object system.text.asciiencoding
$UDPPacket = 0x03
[void]$UDPClient.Send($UDPPacket,$UDPPacket.length)
$UDPEndpoint = New-Object system.net.ipendpoint([system.net.ipaddress]::Any,0)
Try {
$BytesRecived = $UDPClient.Receive([ref]$UDPEndpoint)
[string]$Response = $ToASCII.GetString($BytesRecived)
$res = ""
If ($Response) {
$Response<# = $Response.Substring(3,$Response.Length-5)
$i = 0;
$Response.Split(";") |
ForEach {
if ($i % 2 -eq 0)
{
Write-Host "col:"$_
}
else
{
Write-Host "val:"$_
}
$i+=1
}#>
$UDPClient.close()
}
}
Catch {
$UDPClient.Close()
}
}
End {
}
}
QuerySQLListner webserver