ProClub Posted February 20, 2006 Share Posted February 20, 2006 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.txtfor /f "tokens=1-2 delims=:" %%i in (ip1.txt) do echo %%j > ip2.txtdel ip1.txtfor /f "tokens=1-4 delims=. " %%i in (ip2.txt) do (nslookup %%i.%%j.%%k.%%l >ns.txtset IP=%%i.%%j.%%k.%%l)del ip2.txtfor /f "skip=2 tokens=2 delims=: " %%i in (ns.txt) do if not %%i==%IP% set DNS=%%idel ns.txtThe 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=%%Iafterwards. Note, that the desired computer name will be set in the %ComputerName% variable.Hope, this helps.J Link to comment Share on other sites More sharing options...
hardwaregeek Posted February 20, 2006 Share Posted February 20, 2006 I use wsname.exe. It works for me. Thanks for the script. I will try out. Link to comment Share on other sites More sharing options...
ProClub Posted February 21, 2006 Author Share Posted February 21, 2006 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? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now