Link to home
Create AccountLog in
Avatar of nicholso
nicholso

asked on

DNS lookup from within VB 6.0

We have an app which talks SNMP with a remote host. At connect time the user has to enter an ip address (dotted quad). I'd like to let them enter the plaintext hostname and let our app do the name->address translation.

does anyone know of something that already exists in VB or winsock APIs to do this?
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of kuk010998
kuk010998

The WinSock *control* (or the higher-level msinet.ocx) will look up host names automatically for you. It will also return a host name after you successfully connect with an IP number.

However, if you want do do *only* the DNS lookup without actually sending packets to the host in question, then you'll need to use the API directly. In that case, yell an I'll add a class module that does just that. Or, if you need more than just one IP to a name or vice versa, the control will not do, but my class will.

Oops, mcrider was quicker - his code seems good, too on a first glance, my only complaint'd be that CvtIPAddrClng could be substituted more elegantly by a function exported by the winsock DLL itself...
Avatar of nicholso

ASKER

thanks. Yeah it's way too much code for my purposes, but I was able to strip it down and works great.

thanks again.
And if you ever need it, you have the code to ping systems... One of the cooler functions in that code I gave you is "IsHostAlive".  It returns a TRUE or a FALSE if the host passed on the argument can be connected to...

Thanks for the points! Glad I could help!


Cheers!®©