Getting nslookup info into Access

B

BruceS

Hi!

I need to translate dot-format IP addresses into alpha domain info, e.g.
188.23.24.1 into "ads1.highway.telekom.at". There is a command prompt
command "nslookup" that performs this function, but I want to do it from
within Access so that I can automate the process.

Does anyone have any ideas?

Thanks,
Bruce
 
V

vanderghast

In theory, you can use dnsapi.dll, with W2000, XP, or newer OS. I have never
used it, but under the Framework, there is a nice method just for that:
System.Net.Dns.GetHostEntry. I have tried to find the equivalent in the good
old API style, but found nothing relevant. The reverse, though, is available
at vbnet.mvps.org, under "gethostbyname: Resolve Host Name to IP Address"


Vanderghast, Access MVP
 
J

Jack Leach

I could have swore somewhere I had a link with code that would return the
values returned by a cmd.exe command. I don't seem to have it here, so I'll
have to check my house when I get home.

If I remember correctly, it used an array to collect any lines returned...
say you shelled "Cmd.exe Dir *.*" - it would take all of the files returned
by cmd and put them into the vba array. I have no idea how, and hopefully
I'm not imagining this.

If I can find this, you should be able to use that to run the command line
and have the command line value returned to vba.

I'll report back in a few hours, one way or the other.
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

J

Jack Leach

Well I still haven't made it home to see about that link, but curiousity got
the better of me here and it seems as though STDIN/STDOUT (standard
input/output textstreams ????) are along the lines of what you may need.

Interesting stuff here... rather deep.

Maybe between the other two threads I posted and the STDIN/STDOUT keywords
you can find some more info online (of the two posts, the actual code to do
this is very very similar... a good sign).

In the meantime I'll keep [playing around with this, but in all honesty I
doubt I'll have the ambition to actually see if I can get it to work at any
point in the near future.


Good luck!!

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

and finally, the code I thought I had a link to....

http://www.j.nurick.dial.pipex.com/Code/VBA/vbPerlish.htm

I haven't tried this one either, but if you want to get into it, the
techtips forum link has a complete breakdown of everything going on... its
far more advanced than the above link.

The link above apparently writes the output to a text file when the command
is shelled, and then uses vba to read the text file. IMHO, this way is
probably less secure than the API method used by the other two links I've
posted... in the other links are some examples from posters explaining some
of the reasons. Thereagain, the code in the other two links are stated as
"proof of concept" and not tried and tested... and the above link is by far a
lot easier to digest.

good luck!
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
B

BruceS

Thanks, guys! They pulled me off of this yesterday for something else, but
I'll give your suggestions a try tonight or tomorrow. Will let you know what
works!

Best,
Bruce
 
B

BruceS

Vanderghast,

I found code at VBNet (GetHostNameFromIP) that was exactly what I was
looking for, but it won't initialize properly for me in Access 2003. Have
sent them an email asking for help.
Meanwhile, can you provide guidance on how to call the
System.Net.Dns.GetHostEntry function from dnsapi.dll? That seems like the
most efficient way to do what I'm trying to do.

Thanks,
Bruce
 
B

BruceS

Jack,

Thanks for all of the input! Trying to isolate the proper text from the
return is an option, but I'd rather go with a more direct approach such as
using the .dll. That is, assuming that I can get it to work!

If not, the link you gave me here is a good fallback.

Best,
Bruce
 
V

vanderghast

System.Net.Dns.GetHostEntry, I only mentioned it as possible reference,
since it implies you use the framework (dotNet) and to be able to use it
inside VBA, you would need to encapsulate the code to be usable by COM (as a
COM library). So, only to be used at the last resort only, if every thing
else fails. It is not 'that' complicate to do, though, once you know the
techniques involved, but note that it will also mean that your application
need an exterior dll, which is not necessary allowed in each and every
company (for evident security reasons).


Vanderghast, Access MVP
 
B

BruceS

Well, kills that idea. It's beyond what I can do. Hopefully I can get the
vbNet code to run.

If you have a spare minute, would you look at code at
http://www.vbnet.mvps.org/code/network/hostnamefromip.htm ?

It runs without errors, but the function call
ptrHosent = gethostbyaddr(hAddress, 4, AF_INET)
always returns 0. It says its trying to 'obtain a pointer to the HOSTENT
structure that contains the name and address corresponding to the given
network address.'

Without a non-zero value, it can't finish the process.

Thanks,
BruceS
 
T

Tony Toews [MVP]

BruceS said:
If you have a spare minute, would you look at code at
http://www.vbnet.mvps.org/code/network/hostnamefromip.htm ?

It runs without errors, but the function call
ptrHosent = gethostbyaddr(hAddress, 4, AF_INET)
always returns 0. It says its trying to 'obtain a pointer to the HOSTENT
structure that contains the name and address corresponding to the given
network address.'

FWIW the code worked for me.

MsgBox GetHostNameFromIP("209.115.204.52")

which is my web server returned.

mail.granite.ab.ca

which is close enough.

Tony
 
T

Tony Toews [MVP]

BruceS <bruce \at\ springthorpe.org> wrote:

BTW I should add that there are a number of domains hosted on my
webserver. And that may be the case with whatever server you are
trying to visit.

Tony
 
B

BruceS

Wierd...

Based upon it working for you, I deleted the old code, created another new
module, and recopied the code into it. It worked! I guess that's good...but
makes me more parinoid. (But the bit gremlins really ARE out to get me!)

Thanks, Tony, for getting me to take another look.

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top