Jump to content

Recommended Posts

Posted

Hi there!

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


Posted

I don't know about wsname, the doc states it uses the DNS name. What if the DNS name is something like computer007.mydomain.tld? My method sets the computer name to computer007. What about wsname?

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...