ipaddress

package
v0.0.0-...-f116871 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIPv6

func GetIPv6() (net.IP, error)

GetIPv6 returns the IPv6 address of the host where this code is executing

Types

type BTSmartHub2

type BTSmartHub2 struct {
	Config *config.RouterConfiguration
}

The BTSmartHub2 type that has the ability to talk to a BT Smart Hub 2 to retrieve a public IPv4 address

request url: http://192.168.1.254/nonAuth/wan_conn.xml

sample xml response: <status>

<!-- REAL -->
<wan_conn_status_list type="array" value="[['connected%3B64%3Bpass'],

['disconnected%3B0%3Bpass'], ['disconnected%3B0%3Bpass'], null]" />

<wan_conn_volume_list type="array" value="[['297625188703%3B282899515695%3B14725673008'],

['0%3B0%3B0'], ['0%3B0%3B0'], null]" />

<wan_linestatus_rate_list type="array" value="[['DOWN','ADSL','G%2EDMT','0','0','0','0','0','0','0','0','0','0','0','0','fast'],

null]" />

<wlan_channel_list type="array" value="[['6','0','6'],

['6','0','6'], ['6','0','6'], ['6','0','6'], ['6','0','6'], ['36','0','36'], ['36','0','36'], ['36','0','36'], ['36','0','36'], ['36','0','36'], null]" />

<curlinkstatus type="array" value="[['connected%3B47'],

['disconnected%3B0'], ['disconnected%3B0'], null]" />

<sysuptime value="849301" />
<status_rate type="array" value="[['1000000000%3B1000000000%3B0%3B0'],

['0%3B0%3B0%3B0'], ['0%3B0%3B0%3B0'], null]" />

<wan_active_idx value="0" />
<link_status value="disconnected%3Badsl%3B0" />
<ip4_info_list type="array" value="[['81%2E255%2E255%2E255%3B255%2E255%2E255%2E255%3B172%2E16%2E13%2E79%3B81%2E139%2E56%2E100%3B81%2E139%2E57%2E100'],

['0%2E0%2E0%2E0%3B0%2E0%2E0%2E0%3B0%2E0%2E0%2E0%3B0%2E0%2E0%2E0%3B0%2E0%2E0%2E0'], ['0%2E0%2E0%2E0%3B0%2E0%2E0%2E0%3B0%2E0%2E0%2E0%3B0%2E0%2E0%2E0%3B0%2E0%2E0%2E0'], null]" />

<ip6_lla_list type="array" value="[['fe80%3A%3Afe80%3Afe80%3Afe80%3Afe80%2F10'],

['%3A%3A%2F0'], ['%3A%3A%2F0'], null]" />

<ip6_gua_list type="array" value="[['2a00%3A2a00%3A2a00%3A2a00%3A%3A1%2F64%3B2a00%3A%3A221%3A5ff%3A2a00%3A2a00'],

['%3A%3A%2F0%3B%3A%3A'], ['%3A%3A%2F0%3B%3A%3A'], null]" />

<ip6_rdns_list type="array" value="[[null],[null],[null]]" />
<!-- END_REAL -->
<!--for home page, login lock-->
<locktime value="1" />
<!--END for home page, login lock-->

</status>

func (BTSmartHub2) GetPublicIPAddresses

func (ipProvider BTSmartHub2) GetPublicIPAddresses() (net.IP, net.IP, error)

GetPublicIPAddresses performs a HTTP request to a BT smart hub 2 router to retrieve and return the public IP address and calls GetIPv6 to return the current IPv6 address of the host where this code is executing

func (BTSmartHub2) LogIPAddresses

func (ipProvider BTSmartHub2) LogIPAddresses(ipv4, ipv6 net.IP)

LogIPAddresses logs the public IP address

func (BTSmartHub2) String

func (ipProvider BTSmartHub2) String() string

String implements the Stringer interface to return the name of this IAddressProvider

type Default

type Default struct{}

The Default type that has the ability to talk to api.ipify.org to retrieve a public IPv4 address This type acts as a fallback in the event of there being no configured json router section publicIPv4Provider

request url: https://api.ipify.org

sample json response: 255.255.255.255

func (Default) GetPublicIPAddresses

func (ipProvider Default) GetPublicIPAddresses() (net.IP, net.IP, error)

GetPublicIPAddresses performs a HTTP request to https://api.ipify.org to retrieve and return the public IPv4 address and calls GetIPv6 to return the current IPv6 address of the host where this code is executing

func (Default) LogIPAddresses

func (ipProvider Default) LogIPAddresses(ipv4, ipv6 net.IP)

LogIPAddresses logs the public IP addresses

func (Default) String

func (ipProvider Default) String() string

String implements the Stringer interface to return the name of this IAddressProvider

type IAddressProvider

type IAddressProvider interface {
	// GetPublicIPAddresses returns public IP addresses
	GetPublicIPAddresses() (net.IP, net.IP, error)
	// LogIPAddresses logs the public IP addresses
	LogIPAddresses(net.IP, net.IP)
}

IAddressProvider describes the interface of a type able to return the public facing IP address in use where this code is running

type RouterStatus

type RouterStatus struct {
	Ip4InfoList struct {
		Text  string `xml:",chardata"`
		Type  string `xml:"type,attr"`
		Value string `xml:"value,attr"`
	} `xml:"ip4_info_list"`
}

RouterStatus is partial model of xml response returned by a BT smart hub 2 /nonAuth/wan_conn.xml request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL