getserviceip

Crates.iogetserviceip
lib.rsgetserviceip
version0.1.2
sourcesrc
created_at2024-09-21 20:41:58.283677
updated_at2024-09-26 16:54:22.98892
descriptionWeb service to get IP addresses from devices.
homepage
repositoryhttps://github.com/sukkis/getserviceip
max_upload_size
id1382458
size98,590
Petteri (sukkis)

documentation

README

getserviceip

getserviceip is a Rust-based web service that provides an endpoint to validate and return IP information. It uses the Actix-web framework to handle HTTP requests.

As an example, you might have a Raspberry Pi in local network that gets IP assigned by DHCP, and you reach the device with ssh. If the address for you device changes, you might not be able to connect it. Instead you could set up a cronjob in the Raspberry Pi to frequently send the IP information to getserviceip. You will always know where your devices can be reached.

Features

  • Health Check Endpoint: A simple endpoint to check if the service is running.
  • IP Information Endpoint: Validates and returns IP information provided in the request body.
  • List All Endpoint: Returns all the IP information that the service has gathered.

Endpoints

Health Check

  • URL: /health_check
  • Method: GET
  • Response: Returns a plain text "OK" if the service is running.

Example

curl http://localhost:8087/health_check

Response:

OK

List all

  • URL: /list_all
  • Method: GET
  • Response: Returns as JSON all the IP information that the service has gathered.

Example

curl http://localhost:8087/list_all

Response:

[
    {
        "hostname": "example1.com",
        "ip_v6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
        "ip_v4": "192.168.0.1"
    },
    {
        "hostname": "example2.com",
        "ip_v6": "2001:0db8:85a3:0000:0000:8a2e:0370:7335",
        "ip_v4": "192.168.0.2"
    }
]

Receive IP info

  • URL: /ip
  • Method: POST
  • Request Body: JSON object containing hostname, ip_v6, and ip_v4.
  • Response: Returns the same JSON object if the information is valid, otherwise returns an error message.

Example

curl -X POST http://localhost:8087/ip -H "Content-Type: application/json" -d '{
  "hostname": "example.com",
  "ip_v6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
  "ip_v4": "192.168.1.1"
}'

Response:

{
  "hostname": "example.com",
  "ip_v6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
  "ip_v4": "192.168.1.1"
}

Running the Service

To run the service, use the following command:

cargo run

The service will start on http://localhost:8087.

Dependencies

License

This project is licensed under the GPL v3 license. See the LICENSE file for details.

Commit count: 40

cargo fmt