gns

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

README

gns

介绍

使用Go编写的网络模块

功能清单
状态检测
  • TCP/UDP端口检测
  • 网站/网址状态检测(可自定义状态码)
  • PING检测
  • 批量PING检测
信息获取
  • 本机IP地址获取
  • 本机互联网出口地址获取
其他
  • 文件下载(只建议下载小文件,如需下载大文件请使用gdf项目)

使用说明

安装
go get -u gitee.com/liumou_site/gns
使用方法

直接参照单元测试Demo

状态检测Demo

信息获取Demo

问题反馈

点击链接加入QQ群聊【坐公交也用券

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(url string, save string) bool

DownloadFile 是一个下载文件的功能,通过传入url和保存路径即可开始下载,结果返回布尔值 save 保存路径,默认当前目录下以URL后缀文件名进行保存

func IpCutEndId added in v1.2.3

func IpCutEndId(ip string) (index int, err error)

IpCutEndId 通过传入一个完整IP(192.168.1.1)截取该IP的ID(1)

func IpCutSubnet added in v1.1.6

func IpCutSubnet(ip string) string

IpCutSubnet 通过传入一个完整IP(192.168.1.1)截取该IP的网段(192.168.1)

func IpGenerateIndex added in v1.2.4

func IpGenerateIndex(ip string, ipSlice []int) (IpList []string, err error)

IpGenerateIndex 通过传入一个标准IP和切片列表生成IP进行排序处理 [1 3 7 10 20 5 6] [192.168.1.1 192.168.1.3 192.168.1.5 192.168.1.6 192.168.1.7 192.168.1.10 192.168.1.20]

func IpGenerateList added in v1.1.6

func IpGenerateList(subnet string, start, stop uint8) ([]string, error)

IpGenerateList 生成IP列表,传入子网(192.168.1),开始IP(0),结束IP(255)用于生成一个列表切片

func IpParse added in v1.1.6

func IpParse(s string) (net.IP, int)

IpParse 判断IP是否规范及类型(4/6)

func IpSort added in v1.2.4

func IpSort(ip string) (index int, err error)

IpSort 通过传入一个IP切片进行排序处理

func IpStrGetAddr added in v1.3.0

func IpStrGetAddr(text string) (error, []net.IP)

IpStrGetAddr 从字符串中提取所有IPV4地址

func IsDockerDevice added in v1.3.1

func IsDockerDevice(eth string) bool

IsDockerDevice 判断是否Docker网卡

func IsLoopbackV4 added in v1.3.1

func IsLoopbackV4(ipAddr string) bool

IsLoopbackV4 判断是否属于回环

func MarshalMsg added in v1.1.7

func MarshalMsg(req int, data []byte) ([]byte, error)

func OpenUrl added in v1.2.7

func OpenUrl(url string)

OpenUrl Linux使用浏览器打开URL

func Ping added in v1.1.7

func Ping(host string, req int, debug bool) error

Ping 通过net模块构造数据实现icmp请求达到Ping检测主机在线的效果

func PingConcurrency

func PingConcurrency(sub string, start, stop int) (res bool, use, notUsed string)

PingConcurrency 这是一个高并发的Ping检测功能 sub 子网,例如: 10.1.1 icmp/stop 开始及结束 use 被使用的主机 notuse 未使用的主机(字符串返回: 10.1.1.2 10.1.1.3)可以使用切片切割数据 res 是否进入检测条件

func PortTcpStatus added in v1.3.0

func PortTcpStatus(ip, port string, out time.Duration) bool

PortTcpStatus 是一个检测TCP端口是否开启的功能

func PortUdpStatus added in v1.3.0

func PortUdpStatus(ip, port string, out time.Duration) bool

PortUdpStatus 是一个检测TCP端口是否开启的功能(目前并不准确)

func SliceToString

func SliceToString(ls []string, sep string) string

SliceToString 字符串列表转字符串(seq: 拼接符,可以用: 空格 / _ @ 之类,具体请以实际需求设置)

func Version

func Version()

Types

type Api

type Api struct {
	UseTxt, NotUsed string         // 使用/没使用的ip清单
	Req             *http.Request  // 请求实例
	Resp            *http.Response // 响应实例
	Err             error          // 错误
	// contains filtered or unexported fields
}

Api 定义GNS结构体

func NewNet added in v1.2.6

func NewNet() *Api

NewNet 初始化配置

func (*Api) HttpStatus

func (api *Api) HttpStatus(host string) bool

HttpStatus 是一个使用tcp检测网页是否正常访问的功能 host: 需要检查的主机

func (*Api) HttpStatusUrl

func (api *Api) HttpStatusUrl(url string) error

func (*Api) HttpStatusUrlBool added in v1.3.2

func (api *Api) HttpStatusUrlBool(url string) bool

HttpStatusUrlBool 使用Get方式判断网页是否正常访问(使用code指定状态)

type IpApi

type IpApi struct {
	// contains filtered or unexported fields
}

func NewIp added in v1.2.6

func NewIp() *IpApi

NewIp 初始化IP参数

func (*IpApi) GetIntranetAddressList

func (api *IpApi) GetIntranetAddressList() (bool, []string)

GetIntranetAddressList 获取本机所有IP列表

func (*IpApi) GetUseIP

func (api *IpApi) GetUseIP() (string, error)

GetUseIP 通过Udp协议发送请求获取正在使用的IP(默认路由IP,如果做了自定义路由并且设置了目标服务器,则会获取到对应的本地IP)

type PingCmdAPI added in v1.2.2

type PingCmdAPI struct {
	Realtime   bool // 是否开启实时刷新
	ExitStatus bool // 是否打印每次退出代码
	// contains filtered or unexported fields
}

func NewPing added in v1.2.6

func NewPing(count, timeout int) *PingCmdAPI

func (*PingCmdAPI) PingCmd added in v1.2.2

func (p *PingCmdAPI) PingCmd(host string) error

PingCmd 通过调用系统命令进行ping检测

func (*PingCmdAPI) PingLoss added in v1.3.0

func (p *PingCmdAPI) PingLoss(host string, pack int) (err error, loss int)

PingLoss 通过调用系统命令进行ping检测丢包率

type Reply added in v1.1.7

type Reply struct {
	Time  int64
	TTL   uint8
	Error error
}

Jump to

Keyboard shortcuts

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