I wrote a little script to get the domain name of my local computer on the network. Since this was somewhat of a headache for many, so I post my script here.
Note: this runs on WinXP only, as far as I know. Feel free to optimize it. It's a Q&D script.
ipconfig | find "IP Address" > ip1.txt for /f "tokens=1-2 delims=:" %%i in (ip1.txt) do echo %%j > ip2.txt del ip1.txt for /f "tokens=1-4 delims=. " %%i in (ip2.txt) do ( nslookup %%i.%%j.%%k.%%l >ns.txt set IP=%%i.%%j.%%k.%%l ) del ip2.txt for /f "skip=2 tokens=2 delims=: " %%i in (ns.txt) do if not %%i==%IP% set DNS=%%i del ns.txt
The DNS name is stored in %DNS%. You can use it with compname if you like. If you want to truncate it to the computer name, use:
for /f "delims=. tokens=1" %%I IN ("%DNS%") DO set ComputerName=%%I
afterwards. Note, that the desired computer name will be set in the %ComputerName% variable.
Hope, this helps.
J



Help
Back to top








