Making a reverse lookup IP Tool


Creating a Reverse Lookup IP Tool

In this tutorial, we will create a simple reverse lookup IP tool similar to icanhazip.com. This tool will allow users to find their public IP address.

Prerequisites

Before we start, ensure you have the following installed:

  • Node.js
  • npm (Node Package Manager)

Step 1: Set Up Your Project

First, create a new directory for your project and navigate into it:

mkdir reverse-ip-tool
cd reverse-ip-tool

Initialize a new Node.js project:

npm init -y

Step 2: Install Required Packages

We will use the express package to create a simple web server. Install it using npm:

npm install express

Step 3: Create the Server

Create a new file named index.js and add the following code:

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
  res.send(`Your IP address is: ${ip}`);
});

app.listen(port, () => {
  console.log(`Server is running at http://localhost:${port}`);
});

Step 4: Run the Server

Start your server by running the following command:

node index.js

Open your web browser and navigate to http://localhost:3000. You should see your IP address displayed on the screen.

Conclusion

You have successfully created a simple reverse lookup IP tool. This basic example can be expanded with additional features such as logging, IP geolocation, and more. Happy coding!