To begin with, you should know what domain controller your workstation has logged into. This machine logon establishes the "secure channel" between your machine and the domain. You can use an old tool that is still around called nltest.
C:\Windows>nltest /sc_query:contoso.com
Flags: 30 HAS_IP HAS_TIMESERV
Trusted DC Name \\DC1.contoso.com
Trusted DC Connection Status Status = 0 0x0 NERR_Success
The command completed successfully
This output shows the status of your secure channel, and the name of the domain controller you are querying. You will need to provide the name of the domain you are connected to. FQDN domain name or NETBIOS domain name should work fine.
This script will provide two functions, one port checker and one function to run to test your connection. Run Test-DomainControllerPorts with your domain name (or leave it blank for auto detect). The script returns the name of the DC that you are connected to, along with 2 arrays of ports that are open and another of ports that aren't responding.
function tcpt ([string]$serv, [string]$p) {
$result = $false
try {
$conn = new-object system.net.sockets.tcpclient($serv,$p)
if ($conn.connected) { $result = $true } else { result = $false }
$conn.close()
} catch {
$result = $false
}
$conn = $null
return $result
}
function test-DomainControllerPorts {
param (
$domainname = (gwmi win32_computersystem).domain
)
$secureChannelDC = (nltest /sc_query:$domainname |
where {$_ -match "Trusted DC Name"}).split("\\") |
where {$_ -match $domainname}
$secureChanneldc = $securechanneldc.trim()
$functionalports = @()
$nonFunctionalPorts = @()
$portsToCheck = ("53", "88", "135", "137", "139", "389", "445", "464", "3268", "636", "3269")
foreach ($port in $portsToCheck) {
$portstat = tcpt $secureChannelDC $port
if ($portstat) {
$functionalports += $port
} else {
$nonfunctionalPorts += $port
}
}
$result = new-object PSObject
add-member -inp $result NoteProperty DomainController $secureChannelDC
add-member -inp $result NoteProperty OpenPorts $functionalports
add-member -inp $result NoteProperty UnOpenPorts $nonfunctionalports
out-default -inp $result
}
Update for later OS's (high than win 2008), some of the ports above are legacy and wouldn't be open on many domain controllers (such as 137, 139)
No comments:
Post a Comment