Solved

Using VBA to produce output from NSLOOKUP

Posted on 2006-11-03
7
1,413 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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 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…

708 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

20 Experts available now in Live!

Get 1:1 Help Now