gohack

package module
v0.0.0-...-9c3645e Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: MIT Imports: 23 Imported by: 0

README

gohack

自用go库

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChinaIP = map[string][]string{}/* 370 elements not displayed */

ChinaIP 表示中国各省市IP段(省全,市不全)

View Source
var CityCode = map[string]string{}/* 3508 elements not displayed */

CityCode 为城市编码和城市映射表

Functions

func BeginOfMonth

func BeginOfMonth() (firstDayOfMonth time.Time)

BeginOfMonth 当前月开始

func Cidr2Range

func Cidr2Range(cidr string) (ipStart string, ipEnd string)

Cidr2Range 将cidr类型的地址转换成IP地址段表示

func Combinations

func Combinations(list Replacer, selectNum int, repeatable bool, bufSize int) (c chan Replacer)

Combinations 组合数生成器 @list: 元素列表 @selectNum: 生成的组合数长度 @repeatable: 是否允许重复元素 @bufSize: 消息通道缓存大小

func ConvertToStruct

func ConvertToStruct(in, out interface{}) (err error)

ConvertToStruct 通过json序列化反序列化的方式转换不同结构体 @in: 待转换的结构体 @out: 转换后的结构体

func Crc32

func Crc32(str string) (hexValue string)

Crc32 计算字符串的crc值

func Date

func Date(format string, timestamps ...int64) (formatDate string)

Date 格式化字符串 @timestamp: 时间戳 例1:Y-m-d 返回2017-08-24 例2:y年m月d日 返回 17年08月24日 例3:H:i:s 返回 17:04:57

func Datetime2Ts

func Datetime2Ts(layout, timeString string) (timestamp int64, err error)

Datetime2Ts 将时间格式字符串转换为时间戳 @layout: 参考 "2006-01-02 15:04:05" 这个值做格式变换 @timeString: 时间戳字符串

func DiffDayNum

func DiffDayNum(startDay string, endDay string) (dayNum int)

DiffDayNum 计算两个日期之间差多少天

func FakeIP

func FakeIP(location string) (ip string)

FakeIP 按照指定的location(省或市)生成随机IP

func FormatTime

func FormatTime(t time.Duration) (formatTime string)

FormatTime 将普通时间类型转换为格式化的字符串

func GetCidrHostNum

func GetCidrHostNum(maskLen int) (ipNum uint)

GetCidrHostNum 计算得到CIDR地址范围内可拥有的主机数量

func GetResponseText

func GetResponseText(resp *http.Response) (string, error)

GetResponseText 从响应结构体中获取文本字符串,包括自动处理gzip

func HTTPBuildQuery

func HTTPBuildQuery(queryArr map[string]string) (queryString string)

HTTPBuildQuery 将map转换为url查询参数形式

func HTTPRawViaProxy

func HTTPRawViaProxy(protocol, host, port, raw, proxy string, timeout int) (response *http.Response, err error)

HTTPRawViaProxy 用于发送原始报文 @protocol: http 或 https @host: 主机IP或域名 @port: 端口 @raw: burpsuite之类的工具抓到的原始报文 @proxy: 指定代理,格式为 type://host:port, 例如: socks5://127.0.0.1:1080, 无代理则传入空字符串 @timeout: 超时时间,请求并发量较大时,timeout最好大一点

func HTTPViaProxy

func HTTPViaProxy(method, url, data, proxy string, timeout int, headers *http.Header, cookie *http.Cookie) (response *http.Response, err error)

HTTPViaProxy 通过proxy发包,支持socks、http、https等类型的proxy @method: 值为 OPTIONS 或 GET 或 HEAD 或 POST 或 PUT 或 DELETE 或 TRACE 或 CONNECT @url: 请求URL @data: HTTP Body 中的数据 @proxy: 指定代理,格式为 type://host:port, 例如: socks5://127.0.0.1:1080, 无代理则传入空字符串 @timeout: 超时时间,请求并发量较大时,timeout最好大一点 @headers: http.Header类型指针,表示请求头 @cookie: http.Cookie类型指针,表示请求cookie

func HmacSha1

func HmacSha1(key, str string) (hexValue string)

HmacSha1 计算字符串的HmacSha1值 @key: 计算hmac的key @str: 原始字符串

func IP2Int

func IP2Int(ip string) int64

IP2Int IP地址转数字

func InArray

func InArray(obj interface{}, target interface{}) bool

InArray 判断某个值是否在数组中 @obj: 待查找的值 @target: 目标数组

func Int2IP

func Int2IP(ip int64) string

Int2IP 数字转换IP地址

func IntVal

func IntVal(val interface{}) (output int)

IntVal 把其他类型转为int @val: 需要转换的值

func Md5

func Md5(str string) (hexValue string)

Md5 计算字符串的MD5值

func NewRand

func NewRand() *rand.Rand

NewRand 实例化随机数结构体,源为时间微秒

func Now

func Now() time.Time

Now 返回上海时区的时间

func Permutations

func Permutations(list Replacer, selectNum int, repeatable bool, bufSize int) (c chan Replacer)

Permutations 生成排列数 @Replacer: 元素列表 @selectNum: 排列长度 @repeatable: 是否允许元素重复 @bufSize: 消息通道缓存大小

func QueryStringToMap

func QueryStringToMap(query string) (ret map[string]string, err error)

QueryStringToMap 将url查询参数转换为map

func RandIPInCidr

func RandIPInCidr(cidr string) (ip string)

RandIPInCidr 在CIDR地址范围内生成一个随机IP

func RandIPInRange

func RandIPInRange(minIP, maxIP string) (ip string)

RandIPInRange 在给定的IP地址范围内随机生成一个IP,minIP和maxIP可以是.分隔的IP表示,也可以是十进制数字IP表示

func RandString

func RandString(letters string, n int) string

RandString 产生指定长度随机字符串, letters 默认为纯数字 "0123456789"

func Round

func Round(num float64, precise int) (output float64)

Round 保留小数点后几位 @num: 原始数字 @precise: 在小数点后要保留的位数

func Sha256

func Sha256(str string) (hexValue string)

Sha256 计算字符串的sha256哈希值

func Shuffle

func Shuffle(vals []int) (randList *[]int)

Shuffle 打乱 []int 的元素顺序

func SortToQS

func SortToQS(data map[string]string) (sortedQueryString string)

SortToQS 根据字典序排列key-value并生成url查询参数字符串 @data: key-value 的字典

func Str2Time

func Str2Time(str string) int64

Str2Time 通过字符串获取时间戳 例1:newtimes,_ := Str2Time("-1days") 例2:newtimes,_ := Str2Time("+12hours") 例3:newtimes,_ := Str2Time("+1years")

func StrLen

func StrLen(str string) int

StrLen 计算字符串长度 @str: 指定字符串

func StrVal

func StrVal(val interface{}) (output string)

StrVal 把其他类型转为string @val: 需要转换的值

func Time

func Time() int64

Time 获取当前系统时间戳

func Today

func Today() (zeroOclock time.Time)

Today 返回当天0点时间对象

Types

type Float64Replacer

type Float64Replacer []string

func (Float64Replacer) Len

func (fr Float64Replacer) Len() int

func (Float64Replacer) Replace

func (fr Float64Replacer) Replace(indices []int) Replacer

func (Float64Replacer) ToString

func (fr Float64Replacer) ToString() string

type IntReplacer

type IntReplacer []int

IntReplacer 适用元素为int类型

func (IntReplacer) Len

func (ir IntReplacer) Len() int

Len 计算元素数量

func (IntReplacer) Replace

func (ir IntReplacer) Replace(indices []int) Replacer

Replace

func (IntReplacer) ToString

func (ir IntReplacer) ToString() string

ToString 输出字符串

type Replacer

type Replacer interface {
	Len() int
	Replace([]int) Replacer
	ToString() string
}

Replacer 接口

type RuneReplacer

type RuneReplacer []rune

func (RuneReplacer) Len

func (rr RuneReplacer) Len() int

func (RuneReplacer) Replace

func (rr RuneReplacer) Replace(indices []int) Replacer

func (RuneReplacer) ToString

func (rr RuneReplacer) ToString() string

type StringReplacer

type StringReplacer []string

func (StringReplacer) Len

func (sr StringReplacer) Len() int

func (StringReplacer) Replace

func (sr StringReplacer) Replace(indices []int) Replacer

func (StringReplacer) ToString

func (sr StringReplacer) ToString() string

Jump to

Keyboard shortcuts

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