Solved

Using VBA to produce output from NSLOOKUP

Posted on 2006-11-03
7
1,418 Views
Last Modified: 2012-06-27
I'm trying to use a command button in MS Access (as I don't have VB installed at work) to do the following:

1. Open a text file containing IP Addresses
2. Run NSLOOKUP (an executable that displays info for each IP address on screen) against each IP address
3. Print the returned info for each IP Address to a new text file and do this until reaching the end of the IP Address file.

I'm familiar with how to open a file for input and output, but not with how to run the NSLOOKUP from code or how to print the output of the NSLOOKUP to a new text file.

Any help is appreciated.

Tim
0
Comment
Question by:tilacakr
  • 5
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
eheimer earned 250 total points
ID: 17870861
try this:

dim ipaddrs()
dim outputfile as string
outputfile = "c:\nslookup.out"

'insert commands to load ip addresses from file into array

'the command below will append output to the outputfile.  If you want to
'make sure you're starting with a new file, insert command to delete existing file here.

for x = 0 to ubound(ipaddrs) - 1
      Shell Environ$("COMSPEC") & " /c nslookup " & ipaddrs(x) & " >> " & outputfile, 1
next x
0
 

Author Comment

by:tilacakr
ID: 17882253
Refresh my memory...

I know how to open a file for input and output, but forgot how to load it into an array.

Thanks,
Tim
0
 

Author Comment

by:tilacakr
ID: 17883464
Eric,

I'm trying this code reading a line at a time in as I'm familiar with how to do that and my text file will only contain IP addresses. Do you think this will work?

Private Sub Command0_Click()

Dim ff As Integer
Dim outputfile As String
outputfile = "c:\ipconfig.out"

ff = FreeFile
Path = "C:\WINDOWS\System32\ipconfig.exe"

Open "C:\Tim\Test.txt" For Input As #ff

Do Until EOF(ff)
Line Input #ff, ln

Shell Environ$("COMSPEC") & " /c ipconfig " & ln & " >> " & outputfile

DoEvents
Loop

Close #ff

End Sub
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:tilacakr
ID: 17883723
Eric,

Actually I just tested the code (should've done that before my last post) and it worked.

Thanks for the help with the output file.

Tim
0
 

Author Comment

by:tilacakr
ID: 17883981
Eric,

I know I closed this out, but I think I still may have something missing. I took out the ", 1" you had after the ling:

Shell Environ$("COMSPEC") & " /c ipconfig " & ln & " >> " & outputfile

and I only got the first option I used for Ipconfig (have to use IPCONFIG as I'm writing this for someone who has access to nslookup and I do not). I placed the ", 1" back in and I got output to my outputfile of two of the four options.

What is the purpose of the comma and subsequent number in the code?

Thanks,
Tim
0
 

Author Comment

by:tilacakr
ID: 17884161
Correction...

Actually only getting one output despite having many lines to query. They are just concatenating onto the existing file.
0
 
LVL 2

Expert Comment

by:eheimer
ID: 17886510
Sorry for my absense today.  The syntax of the "shell" command is:

Shell (pathname, [windowstyle])

The arguments for windowstyle are:

0 = hide the window
1 = normal focus
2 = minimized with focus
3 = maximized
4 = normal, no focus
6 = minimized, no focus

It doesn't sound like that is related to your problem, though.  I see you have another question opened for this issue.  I'll take a look at it there.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now