Solved

Using VBA to produce output from NSLOOKUP

Posted on 2006-11-03
7
1,424 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

825 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