?
Solved

libcurl and ip resolution

Posted on 2006-05-22
5
Medium Priority
?
211 Views
Last Modified: 2012-08-13
I'm using libcurl in my perl application to download some web sites. I need to know what IP address those web sites resolve to, to know the specific IP that my curl code is hitting. Is there any way to query the libcurl response to see what IP it actually hit, not just the domain?

The main reason for this is to know which load balanced server I'm hitting.

One option would be for me to get the IP address independently, but I wouldn't be guaranteed to get the same IP if the DNS rotates amongst a number. Or I could get the IP address first, then hit the IP address itself, but some domains require that you request the specific domain and not just the ip address.

Anyone have any other ideas?
0
Comment
Question by:timdr
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:ps15
ID: 16738709
do you need this permanently or for diagnosis ?
if you need it only for diagnosis, you could use a tool like Ethereal ( http://www.ethereal.com/ ) and view all HTTP connections.

There's lots of information on how to run it out there  too ( http://www.google.com/search?q=ethereal+tutorial+network )
0
 
LVL 1

Author Comment

by:timdr
ID: 16738835
I need it continuously, each time I make the request, for an application I have. So unfortunately no ethereal or anything like that. Needs to be part of the code basically.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1500 total points
ID: 16740093
use Sys::Hostname;
use Socket;
$addr   = inet_ntoa(gethostbyname($host));
0
 
LVL 1

Author Comment

by:timdr
ID: 16743731
Getting the IP address this way doesn't guarantee that I'm getting the same IP that the libcurl download used does it?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16744882
depends on the gethostbyname() function used by libcurl, i.g. it should be the same (except you have an ancient libc)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question