Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:57:02+00:00 2026-05-15T05:57:02+00:00

How can I programmatically get the Internet IP address? 1) If the computer is

  • 0

How can I programmatically get the Internet IP address?

1) If the computer is directly connected to the Internet using a USB modem.

2) If the computer is connected to the internet via another computer or a modem/router.

I there a way to do both?

P.S. This link gives exactly the Internet IP, but how can I use it in my program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:57:02+00:00Added an answer on May 15, 2026 at 5:57 am
    1. You can write socket code to send an http request to that link.

    2. Under unix/linux/cygwin you can use system(“wget http://www.whatismyip.com/automation/n09230945.asp“); then open the file “n09230945.asp” and read its contents.

    Here is an example of how to make the request using sockets (I modified an online example for this specific purpose). NOTE: It is an example and a real implementation would need to handle the errors better:

    #include <iostream>
    #include <cstring>
    #include <sys/socket.h>
    #include <arpa/inet.h>
    #include <unistd.h>
    
    #define RCVBUFSIZE 1024
    
    int main(int argc, char *argv[])
    {
        int sock;                        // Socket descriptor
        struct sockaddr_in servAddr;     // server address
        unsigned short servPort;         // server port
        char const *servIP;              // Server IP address (dotted quad)
        char const *request;             // String to send to server
        char recvBuffer[RCVBUFSIZE];     // Buffer for response string
        unsigned int requestLen;         // Length of string to send
        int bytesRcvd;                   // Bytes read in single recv()
        bool status = true;
    
        // Initialize port
        servIP = "72.233.89.199";
        servPort = 80;
        request = "GET /automation/n09230945.asp HTTP/1.1\r\nHost: www.whatismyip.com\r\n\r\n";
    
        std::cout << request << std::endl;
    
        /* Create a reliable, stream socket using TCP */
        if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
        {
            status = false;
        }
    
        if (status)
        {
            // Convert dotted decimal into binary server address.
            memset(&servAddr, 0, sizeof(servAddr));
            servAddr.sin_family      = AF_INET;
            servAddr.sin_addr.s_addr = inet_addr(servIP);
            servAddr.sin_port        = htons(servPort);
    
            // Connect to the server.
            if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
            {
                status = false;
            }
        }
    
        if (status)
        {
            // Calculate request length.
            requestLen = strlen(request);
    
            // Send the request to the server.
            if (send(sock, request, requestLen, 0) != requestLen)
            {
                status = false;
            }
        }
    
        if (status)
        {
            std::cout << "My IP Address: ";
    
            if ((bytesRcvd = recv(sock, recvBuffer, RCVBUFSIZE - 1, 0)) <= 0)
            {
                status = false;
            }
    
            if (status && (bytesRcvd >0) && (bytesRcvd < (RCVBUFSIZE-1)))
            {
                recvBuffer[bytesRcvd] = '\0';
                std::cout << recvBuffer << std::endl;
            }
        }
    
        close(sock);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 422k
  • Answers 422k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to be able to sniff the user's location.… May 15, 2026 at 11:26 am
  • Editorial Team
    Editorial Team added an answer Difference between stored procedure and functions in SQL Server ...… May 15, 2026 at 11:26 am
  • Editorial Team
    Editorial Team added an answer This is because when using addEventListener the execution scope is… May 15, 2026 at 11:26 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.