MSFN Forum: Computer name from MAC / local DNS - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Computer name from MAC / local DNS Solved... Rate Topic: -----

#1 User is offline   ProClub 

  • Newbie
  • Group: Members
  • Posts: 25
  • Joined: 30-April 05

Posted 20 February 2006 - 11:06 AM

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


#2 User is offline   hardwaregeek 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 26-January 05

Posted 20 February 2006 - 11:13 AM

I use wsname.exe. It works for me. Thanks for the script. I will try out.

#3 User is offline   ProClub 

  • Newbie
  • Group: Members
  • Posts: 25
  • Joined: 30-April 05

Posted 21 February 2006 - 01:59 AM

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?

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy