mirror of
https://github.com/casjaysdevdocker/ifconfig
synced 2026-01-29 07:11:21 -05:00
🦈🏠🐜❗ Initial Commit ❗🐜🦈🏠
This commit is contained in:
38
iputil/iputil.go
Normal file
38
iputil/iputil.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package iputil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func LookupAddr(ip net.IP) (string, error) {
|
||||
names, err := net.LookupAddr(ip.String())
|
||||
if err != nil || len(names) == 0 {
|
||||
return "", err
|
||||
}
|
||||
// Always return unrooted name
|
||||
return strings.TrimRight(names[0], "."), nil
|
||||
}
|
||||
|
||||
func LookupPort(ip net.IP, port uint64) error {
|
||||
address := fmt.Sprintf("[%s]:%d", ip, port)
|
||||
conn, err := net.DialTimeout("tcp", address, 2*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func ToDecimal(ip net.IP) *big.Int {
|
||||
i := big.NewInt(0)
|
||||
if to4 := ip.To4(); to4 != nil {
|
||||
i.SetBytes(to4)
|
||||
} else {
|
||||
i.SetBytes(ip)
|
||||
}
|
||||
return i
|
||||
}
|
||||
Reference in New Issue
Block a user