A simple Node.js application that captures client request details and provides information about the client, including IP address, user agent, and geo location.
-
Clone the repository:
git clone https://github.com/WhoisGray/ip-information.git
-
Install dependencies:
npm install
-
Start the server:
npm start
-
Open your browser and navigate to
http://localhost:3000
.
docker pull WhoisGray/ip-information:latest
docker run -p 3000:3000 WhoisGray/ip-information:latest
Open your browser and navigate to http://localhost:3000 to access the application.
If you prefer to use Docker Compose, you can use the following docker-compose.yml file:
version: "3"
services:
ip-information:
image: whoisgray/ip-information:latest
ports:
- 3000:3000
Save this content in a file named docker-compose.yml in your project directory, and then run the following command:
docker-compose up
This will start the IP Information application in a Docker container.
This project includes Docker and Docker Compose files, allowing you to easily containerize and run the application in a Docker environment. To use Docker, follow these steps:
- Install Docker on your machine.
- Build the Docker image:
docker build -t ip-information .
- Run the Docker container:
docker run -p 3000:3000 ip-information
- Open your browser and navigate to
http://localhost:3000
.
- Express - Fast, unopinionated, minimalist web framework for Node.js.
- geoip-lite - Lightweight module to look up IP address information.
The application defines the following routes:
-
Root Route ("/")
- This route handles GET requests to the root URL ("/").
- It retrieves the client's public IP address and sends it as a response to the client.
- The IP address is extracted from the request headers, specifically the "x-forwarded-for" header or the remote address.
- The IP address is displayed as a response message, indicating the client's public IP address.
-
"/details" Route
- This route handles GET requests to the "/details" URL.
- It retrieves additional information about the client, including IP address, user agent, and geo-location.
- The IP address is extracted from the request headers, similar to the root route.
- The user-agent information is obtained from the "user-agent" header in the request.
- The geoLocation information is obtained using the "geoip-lite" package based on the client's IP address.
- The response is a JSON object containing the client's IP address, user agent, and geo-location details, along with other request information like URL, method, headers, and cookies.
You can access the root route ("/") to retrieve the client's public IP address and the "/details" route to obtain more comprehensive client information.
Feel free to modify or add more routes based on your application's requirements.
This project is licensed under the MIT License - see the LICENSE file for details.