I had a requirement to be able to tell which PXE or WDS server my Windows machine had booted from. If a Windows machine boots from PXE, a response packet containing boot server information (such as the IP address and name of the network boot server) is inserted into the registry at HKLM\System\CurrentControlSet\Control\PXE. I simply used a VBScript to grab this IP address and then used NBTSTAT to resolve the name.
' Obtain IP address of PXE from registry
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdregProv")
strKeypath = "SYSTEM\CurrentControlSet\Control\PXE"
strEntryName = "BootServerReply"
objReg.GetBinaryValue HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, arrValue
PXEServerIP = arrvalue(20) & "." & arrValue(21) & "." & arrValue(22) & "." & arrValue(23)
' Resolve PXE Server IP address to name using NBTSTAT
Dim sIP : sIP = PXEServerIP
Dim oWAN : Set oWAN = WScript.Arguments.Named
If oWAN.Exists( "ip" ) Then sIP = oWAN( "ip" )
Dim oWSH : Set oWSH = CreateObject( "WScript.Shell" )
Dim sCmd : sCmd = "nbtstat -A " & sIP
Dim sText : sText = oWSH.Exec( sCmd ).Stdout.ReadAll
Dim PXEServerName : PXEServerName = "Name not resolved"
Dim oRE : Set oRE = New RegExp
oRE.Pattern = "\s*(\w+)\s+<20>"
Dim oMTS : Set oMTS = oRE.Execute( sText )
If 1 = oMTS.Count Then
PXEServerName = oMTS( 0 ).SubMatches( 0 )
End if
' Output PXE Server IP and Name
Wscript.Echo "This machine started via PXE boot from PXE server " & PXEServerIP & " (" & PXEServerName & ")"
