-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d3bdf3
Showing
8 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/netdiscover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Netdiscover | ||
[![](https://godoc.org/github.com/CyCoreSystems/netdiscover/discover?status.svg)](http://godoc.org/github.com/CyCoreSystems/netdiscover/discover) | ||
|
||
Netdiscover is a Golang-based tool and library by which network information can | ||
be discovered on various cloud platforms and bare metal installations. The | ||
typical use case is, when running inside Kubernetes or a container, to discover | ||
the public IP and/or hostname of the node on which the container is running. | ||
This is commonly necessary to configure VoIP applications. | ||
|
||
## CLI tool | ||
|
||
In the root directory can be found a CLI tool which can be used to query network | ||
information. There are two options: | ||
|
||
* `-provider <name>`: if a cloud provider is specified, that provider's | ||
metadata services will be used to determine the network information. | ||
Otherwise, a best-effort approach will be used. | ||
* `-field <name>`: if a field is specified, only that particular network | ||
detail will be returned. Otherwise, a JSON object will be returned | ||
containing all network information which was discovered. | ||
|
||
## Supported providers | ||
|
||
Currently, this tool supports three cloud providers: | ||
|
||
* `aws`: Amazon Web Services | ||
* `azure`: Microsoft Azure Cloud | ||
* `gcp`: Google Cloud Platform | ||
|
||
I am happy to accept pull requests to implement more providers. | ||
|
||
## Supported Fields | ||
|
||
Currently, this tool supports four network data fields: | ||
|
||
* `hostname`: the public hostname of the node | ||
* `privatev4`: the private (internal) IPv4 address of the node | ||
* `publicv4`: the public (external) IPv4 address of the node | ||
* `publicv6`: the public (external) IPv6 address of the node | ||
|
||
|
||
## Examples | ||
|
||
Retrieve the public version 4 IP address of the node instance on GCP: | ||
|
||
``` | ||
netdiscover -provider gcp -field publicv4 | ||
``` | ||
|
||
Retrieve all network information on Amazon Wed Services platform: | ||
|
||
``` | ||
netdiscover -provider aws | ||
``` | ||
|
||
Retrieve the version 6 IP address of a baremetal machine: | ||
|
||
``` | ||
netdiscover -field publicv6 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package discover | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
const ( | ||
awsPrivateIPv4URL = "http://169.254.169.254/latest/meta-data/local-ipv4" | ||
awsPublicIPv4URL = "http://169.254.169.254/latest/meta-data/public-ipv4" | ||
awsHostnameURL = "http://169.254.169.254/latest/meta-data/public-hostname" | ||
) | ||
|
||
// NewAWSDiscoverer returns a new Amazon Web Services network discoverer | ||
func NewAWSDiscoverer() Discoverer { | ||
return NewDiscoverer( | ||
PrivateIPv4DiscovererOption(awsPrivateIPv4), | ||
PublicIPv4DiscovererOption(awsPublicIPv4), | ||
PublicHostnameDiscovererOption(awsHostname), | ||
) | ||
|
||
} | ||
|
||
func awsPrivateIPv4() (net.IP, error) { | ||
return StandardIPFromHTTP(awsPrivateIPv4URL, nil) | ||
} | ||
|
||
func awsPublicIPv4() (net.IP, error) { | ||
return StandardIPFromHTTP(awsPublicIPv4URL, nil) | ||
} | ||
|
||
func awsHostname() (string, error) { | ||
return StandardHostnameFromHTTP(awsHostnameURL, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package discover | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
const ( | ||
azurePrivateIPv4URL = "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/privateIpAddress?api-version=2017-08-01&format=text" | ||
azurePublicIPv4URL = "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-08-01&format=text" | ||
) | ||
|
||
// NewAzureDiscoverer returns a new Google Cloud Platform network discoverer | ||
func NewAzureDiscoverer() Discoverer { | ||
return NewDiscoverer( | ||
PrivateIPv4DiscovererOption(azurePrivateIPv4), | ||
PublicIPv4DiscovererOption(azurePublicIPv4), | ||
) | ||
} | ||
|
||
func azurePrivateIPv4() (net.IP, error) { | ||
return StandardIPFromHTTP(azurePrivateIPv4URL, map[string]string{"Metadata": "true"}) | ||
} | ||
|
||
func azurePublicIPv4() (net.IP, error) { | ||
return StandardIPFromHTTP(azurePublicIPv4URL, map[string]string{"Metadata": "true"}) | ||
} |
Oops, something went wrong.