Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBS - NSLOOKUP

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,65263
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBS - NSLOOKUP
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VBS - NSLOOKUP - 10/20/2008 12:10:07 AM   
  Enparo

 

Posts: 2
Score: 0
Joined: 10/20/2008
Status: offline
This is my first script, and i've run into a problem I'm not able to solve so far.

- Whot does the script do so far
It executes CLI and runs Nslookup command with some additional
parameters. It writes the info to a textfile. Then it will search for a
specific 'trigger' (nameserver) and saves everything to the right into the
textfile. So everything before the first nameserver is deleted and the 1st
nameserver ends up in the first line of the .txt.
- The problem:
I want the script to output only the nameservers, as this is different
for every domain I can't search for a specific word. Also different domains
have different numbers of nameservers.
- Solution?
As the first line of the .txt is the 1st nameserver, could I save this to
another textfile. Then loop it until all nameservers are found.
It saves everthing to the right of Nameserver: (so it wont save
Nameserver) which is good when I loop it will go to the second one.
Next I can stop the loop when (nameserver) isnt found anymore

That was my thought on it. No idea how to accomplish it tho
Need some help here =)


Script
----------------------------------------
Dim objShell
Const ForWriting = 2
Const Createifnotexist = true

Domeinnaam=Inputbox ("Enter a domainname:")

strFilePath = "C:\Documents and Settings\Administrator.TESTSERVER\Bureaublad\vbs.t xt"
Set objFSO = Createobject("Scripting.FileSystemObject")

Set objShell = CreateObject("WScript.Shell")
Set objExec = objshell.Exec ("%comspec% /c nslookup -querytype=ns " & Domeinnaam)

strLookup = objExec.stdout.readall

trigger = "nameserver ="
if instr (1,strlookup,trigger,1) >0 then


position = instr (1,strLookup,trigger)
Strlookup = Right (strLookup,(len(strlookup) -position -len(trigger)))
WScript.echo position

Else
Wscript.echo "Failure!"

End If

Set objFile = objFSO.Opentextfile(strFilepath, ForWriting, Createifnotexist)
Objfile.Writeline strLookup

objFile.Close
WScript.Quit
----------------------------------------------

I'm not english so please... keep it to a level i'll understand.
Help appreciated ..!
 
 
Post #: 1
 
 RE: VBS - NSLOOKUP - 10/20/2008 1:38:39 AM   
  ebgreen


Posts: 5251
Score: 31
Joined: 7/12/2005
Status: offline
COuld you please post an example of what the text file looks like. Change any security sensitive information of course.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Enparo)
 
 
Post #: 2
 
 RE: VBS - NSLOOKUP - 10/20/2008 7:06:06 PM   
  Enparo

 

Posts: 2
Score: 0
Joined: 10/20/2008
Status: offline
Input: google.com

Output:

ns1.google.com
google.com    nameserver = ns2.google.com
google.com    nameserver = ns3.google.com
google.com    nameserver = ns4.google.com

ns1.google.com    internet address = 216.239.32.10
ns2.google.com    internet address = 216.239.34.10
ns3.google.com    internet address = 216.239.36.10
ns4.google.com    internet address = 216.239.38.10
---------------------------------------------------------------
I've going in this direction at the moment: (not working tho, maybe just a lil)

--------------
Dim objShell
Const ForWriting = 2
Const ForReading = 1
Const Createifnotexist = true

Domeinnaam=Inputbox ("Enter a domainname:")

strFilePath = "C:\Documents and Settings\Administrator.TESTSERVER\Bureaublad\vbs.txt"
Set objFSO = Createobject("Scripting.FileSystemObject")

Set objShell = CreateObject("WScript.Shell")
Set objExec = objshell.Exec ("%comspec% /c nslookup -querytype=ns " & Domeinnaam)
  
strLookup = objExec.stdout.readall

trigger = "nameserver ="
if instr (1,strlookup,trigger,1) >0 then
  
   position = instr (1,strLookup,trigger)
   Strlookup = Right (strLookup,(len(strlookup) -position -len(trigger)))
   WScript.echo position

Else
Wscript.echo "Failure!"

End If

Set objFile = objFSO.Opentextfile(strFilepath, 2, Createifnotexist)

Objfile.Writeline "*" & strLookup

objFile.Close


searchprefix = "*"
Do Until objFile.AtEndofStream
   strline = objFile.Readline
   Searchresult = instr(strline, searchprefix)
   If Searchresult > 0 then
       Wscript.echo strline
   end if
Loop

WScript.Quit
---------------
I know this won't work, but here some interesting new output:
Now I have a definded character, Is it possible to write the first line to another .txt and then repeat with the others.
Next problem I'm running into is that the vbs.txt first must be ForWriting and after ForReading, I've read i can only use one.
Ideas?

*ns1.google.com
google.com    nameserver = ns2.google.com
google.com    nameserver = ns3.google.com
google.com    nameserver = ns4.google.com

ns1.google.com    internet address = 216.239.32.10
ns2.google.com    internet address = 216.239.34.10
ns3.google.com    internet address = 216.239.36.10
ns4.google.com    internet address = 216.239.38.10

Thnx in advance

(in reply to ebgreen)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBS - NSLOOKUP Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts