libcurl and ip resolution

Posted on 2006-05-22
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?
Question by:timdr
    LVL 4

    Expert Comment

    do you need this permanently or for diagnosis ?
    if you need it only for diagnosis, you could use a tool like Ethereal ( ) and view all HTTP connections.

    There's lots of information on how to run it out there  too ( )
    LVL 1

    Author Comment

    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.
    LVL 51

    Accepted Solution

    use Sys::Hostname;
    use Socket;
    $addr   = inet_ntoa(gethostbyname($host));
    LVL 1

    Author Comment

    Getting the IP address this way doesn't guarantee that I'm getting the same IP that the libcurl download used does it?
    LVL 51

    Expert Comment

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    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…
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    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…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now