This is a simple Go web service that returns information about the host's network interfaces, including their addresses and types.
- Clone the repository:
git clone https://github.com/akalp/hostNetInfoServer.git- Change into the project directory:
cd clientIpServer- Build the application:
- for linux x64:
GOOS=linux GOARCH=amd64 go build- for windows x64:
GOOS=windows GOARCH=amd64 go build- Set the environment variables (optional):
export HNIS_PORT=8080
export HNIS_IF_PREFIX=en- Run the application:
./hostNetInfoServerBy default, the web service listens on port 8080 and returns information for all network interfaces. You can customize the port and filter the interfaces by prefix using environment variables or command-line flags.
HNIS_PORT(default: 8080): The port on which the web service listens.HNIS_IF_PREFIX(default: ""): The prefix to match for network interface names.
port(default: 8080): The port on which the web service listens.if-prefix(default: ""): The prefix to match for network interface names.
The web service exposes a single endpoint (/) that returns a JSON-encoded list of objects representing the network interfaces and their addresses:
[
{
"name": "en1",
"mtu": 1500,
"flags": "up|broadcast|multicast",
"addresses": {
"ipv4": null,
"ipv6": null
}
},
{
"name": "en0",
"mtu": 1500,
"flags": "up|broadcast|multicast",
"addresses": {
"ipv4": [
"127.0.0.1"
],
"ipv6": [
"::1"
]
}
}
]Each object in the list represents a network interface, and includes the following fields:
name: The name of the interface.mtu: The maximum transmission unit (MTU) of the interface.flags: A comma-separated list of flags that describe the state of the interface (e.g., "up", "broadcast", "multicast", etc.).addresses: An object of objects representing the IP addresses associated with the interface. Each ip address grouped by the type of it (IPv4 or IPv6).
This code is released under the MIT License. See LICENSE.md for details.