Skip to content

Simple command line tool to display your internet facing IP address and location. I use it as a sanity check with my VPN.

Notifications You must be signed in to change notification settings

steve-ttt/ipinfo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ipinfo

A simple C++ program that retrieves and parses IP information from ipinfo.io using Boost.Asio and RapidJSON.

Dependencies

Building

  1. Make sure you have Boost installed on your system.
    1. Debian based systems can install with: sudo apt-get install libboost-all-dev
    2. Red Hat / Fedora systems: dnf install boost.x86_64
  2. Copy the "include/rapidjson" directory from the RapidJson git into this project directory (rename it "rapidjson").
  3. Compile the code using the provided Makefile:
    make 
  4. Install with:
    make install

Running

Simply run the compiled executable:

./ipinfo
or
make run

Output

The program will print the following IP information retrieved from ipinfo.io:


ip = [your_ip_address] city = [your_city] region = [your_region] country = [your_country] Org = [your_serviceProvider] loc = [your_latitude],[your_longitude] timezone = [your_timezone]


Explanation

Networking (Boost.Asio):

The pullData() function uses Boost.Asio to establish a TCP connection to ipinfo.io on port 80. It sends an HTTP GET request to retrieve the IP information in JSON format. The response from the server is read into a boost::asio::streambuf. JSON Parsing (RapidJSON):

The JSON data is extracted from the streambuf and stored in a std::string. RapidJSON is used to parse the JSON string into a rapidjson::Document object. The program then accesses and prints specific fields from the JSON document, such as "ip", "city", "region", etc. Notes You might need to adjust the compiler flags and library linking options based on your system configuration. The program assumes that ipinfo.io is accessible and returns a valid JSON response. Error handling is minimal in this example. You can add more robust error checking and handling if needed.

About

Simple command line tool to display your internet facing IP address and location. I use it as a sanity check with my VPN.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published