Much easier to do in VBScript with string manipulation. Try this:
'************************************************************************************************************************************
Set objShell = WScript.CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("cmd.exe /c ipconfig /displaydns")
Do While Not objScriptExec.StdOut.AtEndOfStream
strOutput = objScriptExec.StdOut.ReadLine()
If InStr(strOutput, "CNAME") Then
myArray= Split(strOutput,".",-1)
WScript.Echo myArray(UBound(myArray)-1) & "." &
myArray(UBound(myArray)) & vbcrlf
End If
Loop
'************************************************************************************************************************************
Chris Bodnar, MCSE
Systems Engineer
Distributed Systems Service Delivery - Intel Services
Guardian Life Insurance Company of America
Email: [email protected]
Phone: 610-807-6459
Fax: 610-807-6003
From: "Derrenbacker, L. Jonathan" <[email protected]>
To: "NT System Admin Issues" <[email protected]>
Date: 03/12/2010 11:52 AM
Subject: Scripting Question - How to go backwards with tokens in
for loop?
I writing a quick script to show what domains are currently in a users dns
cache.
I only want the root domain itself, not anything past that.
So if I run this:
for /F "tokens=*" %%X in ('ipconfig /displaydns') DO echo %%X | find
"CNAME Record" >> list.txt
for /F "tokens=8" %%X in ('type list.txt') DO echo %%X >> list2.txt
list2.txt contains output like this:
map-pb.quantserve.com.akadns.net
techtalkz.com
www-google-analytics.l.google.com
etc, etc, etc
How would I strip out only the last 3 tokens so that I would end up with:
akadns.net
techtalkz.com
google.com
Thanks in advance,
Jon
-----------------------------------------
This message, and any attachments to it, may contain information
that is privileged, confidential, and exempt from disclosure under
applicable law. If the reader of this message is not the intended
recipient, you are notified that any use, dissemination,
distribution, copying, or communication of this message is strictly
prohibited. If you have received this message in error, please
notify the sender immediately by return e-mail and delete the
message and any attachments. Thank you.
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~