We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

DNS Lookup with IP address

MasseyM
MasseyM asked
on
Medium Priority
12,723 Views
Last Modified: 2013-12-25
I have an ip address ###.###.###.### and i want the "friendlier" name for it www.friendlyname.com... How can I do that in ASP?  Source Code please... Please don't post an answer that says "YOu can't"... Thanks.

- Matt
Comment
Watch Question

Commented:
Install perlscript for ASP and then the code is:

<script language=PerlScript RUNAT=Server>
sub GetDomainName
{
      $RemoteHost = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}),AF_INET);
      return $RemoteHost;
}
</script>
<%
DomainName = GetDomainName()
%>



Author

Commented:
I dont have access to install Perscript.. Any way via ASP?

Commented:
Perlscript can be used in ASP, just as you can use VBScript or Javascript.

So perlscript IS ASP :)

Probably yo mean if there is a way in VBScript. The thing is that you have to do some reverse DNS-lookup. You could try and write the VBScript for that your self, or use those which are available.

- Available is the perl routine (if you have perl & perlscript installed
- available is NS-lookup (if you have that installed on your machine). It runs from the command prompt. You could try to use that by calling it from ASP and make it write to a small file on HD, read that file and get the domainname from it. It is not a very elegant way, but it works (i have used it, but not with ASP)

If you would like to have source code for that, I don't have it, you would have to give more then 50 points to make me work on that. You can probably figure the code out yourself.

Commented:
There was something missing in the code using perlscript, so I'll post the working code here, for those who are interested.

Another solution on which I am working is to make a COM object using java, and call that from the ASP. Using java it should be too hard to get the domain name based on the IP address, since java (just like perl) is web-oriented and has inbuilt function for such things.

When I have that working i'll post the java-code and the procedure of registering it at as a COM-object so it can be accesed through ASP.

Anyway, here's the working code with perlscript (it needed a "use Socket" statement).

<script language=PerlScript RUNAT=Server>
use Socket;

sub GetDomainName
{
      $RemoteHost = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}),AF_INET);
      return $RemoteHost;
}
</script>

<%
DomainName = GetDomainName()
Response.write DomainName
%>


Author

Commented:
ok, Still no one understands... I DON NOT have Perscript on my server... I will not have it either.  So, there is no way to do it other than with perl?

Author

Commented:
ok, Still no one understands... I DON NOT have Perscript on my server... I will not have it either.  So, there is no way to do it other than with perl?

Commented:
Well, actually, you could write an ASP component using C++ and ATL. But again, you won't be able to install it since you don't have access to your server configuration. And VBScript will not allow you to do many things ...
Usually, when one has to do something fancy in VBScript, it's time to write an ATL ActiveX (server-side) component. And PerlScript is just a simplest way around that problem, because it's already sort of an ActiveX component.

We once wrote such a component, one that did something that VBScript could never do: connect to a OWS 2.0 server (Oracle) and do transactions, like login, charge points, etc. We knew exactly that VBScript could never do that, so there was no questions like "how to do something like that in ASP ?"
There some limitations to VBScript that can't be resolved w/o resorting to a different level of technology. This seems to be one of them.
I suggest you accept sybe's answer -- it's very logical and by far the most simple.

Commented:
There should be another way: java, as I have pointed out.
The thing is that ASP and VBScript do not offer the functionality that you need for that, so you have to import that functionality from another programming language: perl or java then seem to be the best options, since those are very much internet oriented languages.

I have written a component in Java that does the trick. The only thing is that it bumps on a bug in java 1.02 (so in fact does not do the trick). I can't get it working on a win95 machine, but i'll hope i will get it working on NT4 (after the weekend, you'll have to wait).

By the way, MassyeM, the problem interests me, but your reactions are not very stimulating.

Author

Commented:
sybe, why do I not stimulate you? :)  I am not here to stimulate, I just need some answer ...

Commented:
MasseyM,

I gave you one working answer completely worked out and two suggestions of how to find another solution.

You have not reacted at all on the suggestions that I made. I will repeat them here:

1. Use NSlookup, this is an NT program that runs from the command prompt and does a reverse DNS lookup. Try to make it run with ASP and read the output. You might also try it with Ping, which also returns the domain-name.
2. Use java to make a class file that does the trick. Then register it as a component, so it can be called through ASP.

You could indicate if these suggestions are what you might be looking for, or that you can tell in advance that it is out of the question.

Is NSLookup installed on the machine ?
Can you compile javacode ? you can download compilers for free (or is that too much trouble).
Can you register a component ? or don't you have access for that ?

Author

Commented:
OK, sybe, answer the question and you get the points... I don't care anymore.

Commented:
I think I have a solution for that problem.
It's an ASP component, that should be used in the following way:

=====================================<BR>
<%
  Set obj = CreateObject("DNS.Lookup")
  hostname = obj.GetNameByIP("204.178.210.195")
  error_text = obj.GetErrorText
  Set obj = Nothing
%>

<%=hostname%>
<BR>
Error: <%=error_text%>

<BR>
======================================
<BR>

If you're interested, tell me what you think about it.

You don't have to accept my answer, until you see the component. Besides, this answere will definitely cost more than 50 points (maybe, not much more, though)

Commented:
mitek,

you make me curious, did you make that component yourself ? And what did you use to make it.

I have mine finished too, but I don't get it working on PWS/Windows95, although it should. I'll have to try it on a NT machine. I used Java to do it.

Commented:
Yep. I wrote it just for fun, in Visual C++ with using ATL library. Not that I really cared about answering that particular question, I just wanted to refresh my knowledge of ATL. And it worked :)
I can send you the source code, if you want. It's not a space shuttle, quite simple.

Author

Commented:
Sounds good, but I DONT HAVE ACCESS to install the component... Does it have to be installed into ther server, or can I just create an instance from the ASP source?  -- How much more?

- Matt

Commented:
Yep. I wrote it just for fun, in Visual C++ with using ATL library. Not that I really cared about answering that particular question, I just wanted to refresh my knowledge of ATL. And it worked :)
I can send you the source code, if you want. It's not a space shuttle, quite simple.

Commented:
short answer:
if you can run
regsrv32 component.dll (in other words, to register a component) on the server, you can install it.
If you can't, sorry -- you can't.
(don't worry, i have a feeling it won't go on much longer)

whatever happens -- i'm making my component a shareware thingy.
if someone needs it in the future, it'll be there

the main point, it IS possible. for those, who have access to the server.

Commented:
(sigh. i guess, he didn't like my last remark. i feel rejected :)

Commented:
mitek,

yep, i'd like to have the source code for your thing.

If you're interested, I'll send you mine. The only thing is I still haven't got it working: the problem now is that IIS4 treats java differently. *sigh*.


Commented:
I'll put it to http://www.sarov.com/downloads/lookup.zip
My email is mitek@i3tele.com -- you may send me Java solution if you want.


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

Author

Commented:
You get the points only because you tried very hard.  You got a B only because you were persistant... Please help me get a working example and I will repost another question worth a lot more...
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.