ASP function: gethostbyname! No component needed!

That’s right.

I spent a fair while searching tonight, and can’t seem to get a solution for something so simple. A basic domain lookup to find if a hostname exists, and what IP it is.

Anyway, after a fair bit of poking around, I realised, I already had code to manipulate the command line, so I can probably put that to use here.

I realised, nslookup does what we want, and can do it, well, sort of well.

As a rough start (only got onto this recently):

Function GetHostByName(domain)
Dim oShell, oExec, strStdOut, strStdErr
Set oShell = Server.CreateObject(“WScript.Shell”)
Set oExec = oShell.Exec(“%ComSpec% /c nslookup www.google.com”)
strStdOut = “”
stdStrErr = “”
While Not oExec.StdOut.AtEndOfStream
strStdOut = strStdOut & oExec.StdOut.ReadLine & vbNewLine
Wend

While Not oExec.StdErr.AtEndOfStream
strStdErr = strStdErr & oExec.StdErr.ReadLine & vbNewLine
Wend

‘ To Do: Parse strStdOut & strStdErr to determine if an IP (or IPs) exist, return FALSE on failure (like PHP).

End Function

As I specified above, I still gotta do a bit with it, parsing the result for the IP, or if it doesn’t exist, return FALSE.

But, it sure beats installing foreign components, and beats playing around with parsing error messages.

I can’t believe ASP / VbScript doesn’t already have such a simple function already built in, but none the less, that makes PHP the far more superior language.

PHP is far more flexible and requires less coding when put against ASP, for which functions have to be developped for.

I think the only other enhancements that could be added is reverse lookup, that is, turn IPs to domains!

I find these challenges fun, but still, a waste of time. So much more can be accomplished in other languages.

I also should add, not totally relevant to the above, but Netspace have been pretty bad today.
I had something like 4 drop outs, and a very … slow… patch. Where even Google was slow. Google is never slow. You don’t have multiple data centres of servers all set up to host the Search application, for users to find it “slow”.

On the plus side though, we are sucking down data at a fantastic rate, for what we pay. The free PIPE traffic is fantastic, it just makes so much more data available for such a nice flat price. Over the last 2 months, we really have gotten some good value from our connection!

This entry was posted in Programming, Random. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *