ipgrabber

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

package designed to be a user-friendly way to interact with the various network interfaces of one's computer. this will allow the user to grab the IP address of a given interface, grab all the IPs of all interfaces, etc. this can be very useful when performing network-specific tasks that require interaction on a specific interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPGrabber

type IPGrabber struct {

	// slice holding all the discovered network interfaces on
	// the current system. this excludes the loopback interface.
	Interfaces []net.Interface

	// slice holding all the discovered IP addresses for all
	// the interfaces in the Interfaces slice.
	Discovered []net.IP
}

structure representing the main object that will search for and hold the discovered addresses and interfaces.

func NewGrabber

func NewGrabber() (grabber *IPGrabber, err error)

function designed to create a new IPGrabber, populate both slices and return the pointer to the user. if an error occurs nil and the error will be returned, otherwise the pointer and nil will be returned.

func (*IPGrabber) AddIP

func (grabber *IPGrabber) AddIP(ipaddr net.IP) (err error)

function designed to add an IP address to the list of discovred IP addresses. this first checks if the address was previously discovered/added to the list. if the address is already in the list, it does not add it and returns an error.

func (*IPGrabber) AlreadyFound

func (grabber *IPGrabber) AlreadyFound(ipaddr net.IP) (err error)

function designed to determine if the given IP address is already in the list of discovred addresses. returns error if the address is not in the list, nil if it is in the list.

func (*IPGrabber) GetFirstNonLoop added in v0.0.18

func (grabber *IPGrabber) GetFirstNonLoop() (iface string, err error)

function designed to return the first non-loopback interface from the Interfaces slice. if there is an error or no non-loopback interface is discovered an error will be returned, otherwise the interface name and nil will be returned.

func (*IPGrabber) GrabIPs

func (grabber *IPGrabber) GrabIPs() (err error)

Function designed to acquire all IPv4 network addresses attached to the current machine.

func (*IPGrabber) GrabInterfaceIP

func (grabber *IPGrabber) GrabInterfaceIP(targetiface string) (ipaddr net.IP, err error)

function designed to acquire the IP address of a target interface. this will return the net.IP object and nil if the interface is successfully discovered, otherwise it will return nil and error.

func (*IPGrabber) GrabInterfaces

func (grabber *IPGrabber) GrabInterfaces() (err error)

function designed to populate/repopulate the Interfaces slice of the IPGrabber struct by calling the net.Interfaces function.

func (*IPGrabber) IFacesEmpty

func (grabber *IPGrabber) IFacesEmpty() (empty bool)

function designed to check whether the interface list is empty. returns true/false based on the length of grabber.Interfaces.

func (*IPGrabber) InterfaceExists

func (grabber *IPGrabber) InterfaceExists(ifaceName string) (err error)

function designed to check wheter an interface with a given name exists in the discovered interfaces.

func (*IPGrabber) ListIFaces

func (grabber *IPGrabber) ListIFaces() (err error)

function designed to list out all discovered Interfaces on the current machine. if the interface slice is empty, it will attempt to populate it first.

func (*IPGrabber) ListIPs

func (grabber *IPGrabber) ListIPs() (err error)

Function Name: ListIPs

Author: Thomas Osgood

Description:

Function designed to grab all IPv4 IPs attached to all
network interfaces and list them out.

Input(s):

None

Return(s):

err - error. error or nil.

Jump to

Keyboard shortcuts

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