Jump to content

Computer name from MAC / local DNS


 Share

Recommended Posts

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

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...