We help IT Professionals succeed at work.

How to create an nslookup Function in VBA

6,047 Views
Last Modified: 2013-11-13
I need to write a VBA function which will take in an IP address as a string and then return the resulting reverse lookup as a string and vice versa, that's it nothing fancy.  

The idea is to use this in Excel Spreadsheets to do lookups/reverse lookups on Host Names and IP addresses.

I've seen much harder things doen with the winsock API on this site so hopefully this one is easy.

Can anyone help?
Comment
Watch Question

Software Development Manager
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks Alon,

It took me a while to figure out that the inet_addr function was also needed to convert IP address strings into "long notation".  My initial attempts incorrectly assumed this meant the decimal IP notation.  But once I figured out how to do that the code you provided worked a treat, thanks!

For anyone else who will look to do this, the appropriate addition is:

Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long

Then pass the value returned by inet_addr("1.2.3.4") to Alon's GetHostName() function.
Alon HirschSoftware Development Manager

Commented:
Glad to be able to assist.

Enjoy your day.
Alon

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.