net

package module
v1.0.31 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const BlockHTML = `` /* 774-byte string literal not displayed */
View Source
const Header = `` /* 946-byte string literal not displayed */
View Source
const Tail = `` /* 499-byte string literal not displayed */

Variables

View Source
var ErrBadIP = errors.New("bad ip value")

ErrBadIP indicates ip is not valid

View Source
var ErrBadPort = errors.New("bad port value")

ErrBadPort indicates port is not valid or not authorized

Functions

func CheckBlocked added in v1.0.7

func CheckBlocked(r *http.Request) bool

func DIG

func DIG(domain, remote, clientIP string) ([]dns.RR, error)

DIG like dig

func GetNetClass

func GetNetClass(ip net.IP) string

GetNetClass judges we using tcp4 or tcp6

func GetUploadPage added in v1.0.8

func GetUploadPage(title, path string) string

func IP2Num

func IP2Num(ipstr string) uint32

IP2Num ipv4 to a uint32 number

func IPv62Num

func IPv62Num(ipstr string) (uint64, uint64)

IPv62Num makes a string to 2 uint64 number

func IsIPv6 added in v1.0.7

func IsIPv6(ip string) bool

func Num2IP

func Num2IP(ipnum uint32) string

Num2IP uint32 number to ipv4

func Num2IPv6

func Num2IPv6(network, intf uint64) string

Num2IPv6 makes two uint64 into a string ipv6

func PrintMapValue

func PrintMapValue(msg string, str []string) string

func SplitTimestamp added in v1.0.17

func SplitTimestamp(cookie string) int64

Types

type CookieManager added in v1.0.7

type CookieManager struct {
	CookiePass      string
	ExpireIntervalS int64
}

func NewCookieManager added in v1.0.7

func NewCookieManager(pass, prefix string, exp int64) *CookieManager

func (*CookieManager) CheckCookie added in v1.0.7

func (cm *CookieManager) CheckCookie(r *http.Request, key, cookieKey string) string

func (*CookieManager) ClrCookie added in v1.0.7

func (cm *CookieManager) ClrCookie(w http.ResponseWriter, key string)

func (*CookieManager) SetCookie added in v1.0.7

func (cm *CookieManager) SetCookie(w http.ResponseWriter, key, cookieKey string)

type FakeHandler

type FakeHandler struct {
	FileHandler http.Handler
}

func (*FakeHandler) IsUsingFakeResponse

func (h *FakeHandler) IsUsingFakeResponse(uri string) bool

func (*FakeHandler) ServeHTTP

func (h *FakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FakeResponse

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

func (*FakeResponse) Header

func (f *FakeResponse) Header() http.Header

func (*FakeResponse) Write

func (f *FakeResponse) Write(b []byte) (int, error)

func (*FakeResponse) WriteHeader

func (f *FakeResponse) WriteHeader(statusCode int)

type Stat

type Stat struct {
	TotalInb  int64
	TotalOutb int64
	Inb       int64
	Outb      int64
	Ts        time.Time
	Lock      sync.Mutex
}

Stat gets data every 2 minutes

func (*Stat) Add

func (stat *Stat) Add(n int64, statType StatType)

Add add n to current stat

func (*Stat) ClearOut

func (stat *Stat) ClearOut()

ClearOut clear all statistics and print them

type StatType

type StatType string

StatType in|out

const (
	// StatIn in bounds
	StatIn StatType = "in"
	// StatOut out bounds
	StatOut StatType = "out"
)

type TcpProxy

type TcpProxy struct {
	LocalPort  int
	RemotePort int
	LocalIP    net.IP
	RemoteIP   net.IP
	Stat       *Stat
}

TcpProxy stores ip and port information

func NewProxy

func NewProxy(localP, dstP int, localIP, dstIP string) (*TcpProxy, error)

NewProxy create a proxy of TCP

func (*TcpProxy) AddStat

func (p *TcpProxy) AddStat(n int64, statType StatType)

AddStat goes to stat.Add

func (*TcpProxy) LoopCopy

func (p *TcpProxy) LoopCopy(dst io.WriteCloser, src io.ReadCloser, statType StatType)

LoopCopy copies data until error occur

func (*TcpProxy) Proxy

func (p *TcpProxy) Proxy(c *net.TCPConn)

Proxy starts a server and client

func (*TcpProxy) Run

func (p *TcpProxy) Run() error

Run runs a tcp proxy

func (*TcpProxy) StatCounter

func (p *TcpProxy) StatCounter()

StatCounter reset stat every 2 minutes

type UploaderService added in v1.0.7

type UploaderService struct {
	MaxSize     int64
	MaxMem      int64
	Curr        int64
	BasePath    string
	BaseURL     string
	JumpBackURL string
	NameLen     int
	Expire      time.Duration
	Lock        sync.Mutex
	Map         map[string]time.Time
}

func NewUploadService added in v1.0.7

func NewUploadService(xl *slog.Logger, baseURL, basePath, jump string, maxSize int64, expire time.Duration, nameLen int) *UploaderService

func (*UploaderService) Handler added in v1.0.7

func (u *UploaderService) Handler(w http.ResponseWriter, r *http.Request)

Handler return page if get and write file into disk if post

func (*UploaderService) Patrol added in v1.0.18

func (u *UploaderService) Patrol()

func (*UploaderService) WriteFile added in v1.0.7

func (u *UploaderService) WriteFile(name string, rc io.Reader) (int64, string, error)

WriteFile write reader into file

Jump to

Keyboard shortcuts

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