gns

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

gns

介绍

使用Go编写的网络模块

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

使用说明

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

直接参照单元测试Demo

状态检测Demo

信息获取Demo

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 IpCutSubnet added in v1.1.6

func IpCutSubnet(ip string) string

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

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 PingConcurrency

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

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

func SliceToString

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

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

func TcpPortStatus

func TcpPortStatus(ip string, port, out int) bool

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

func Version

func Version()

Types

type Api

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

Api 定义GNS结构体

func Config

func Config() *Api

Config 初始化配置

func (*Api) HttpStatus

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

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

func (*Api) HttpStatusUrl

func (g *Api) HttpStatusUrl(url string) bool

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

func (*Api) PingStatus

func (g *Api) PingStatus(host string) bool

PingStatus 是一个通过ping检测主机是否在线的功能

type IpApi

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

func IpConfig

func IpConfig() *IpApi

IpConfig 初始化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)

Jump to

Keyboard shortcuts

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