SunnyNet
v1.0.3
Промежуточное программное обеспечение Sunny Network похоже на Fiddler. Является компонентом кроссплатформенного сетевого анализа.
可用于HTTP/HTTPS/WS/WSS/TCP/UDP网络分析 为二次开发量身制作
支持 获取/修改 HTTP/HTTPS/WS/WSS/TCP/TLS-TCP/UDP 发送及返回数据
支持 对 HTTP/HTTPS/WS/WSS 指定连接使用指定代理
支持 对 HTTP/HTTPS/WS/WSS/TCP/TLS-TCP 链接重定向
支持 gzip, deflate, br 解码
支持 WS/WSS/TCP/TLS-TCP/UDP 主动发送数据
Пример кода использования GoLang
package main
import (
"fmt"
"github.com/qtgolang/SunnyNet/SunnyNet"
"github.com/qtgolang/SunnyNet/public"
"time"
)
var Sunny = SunnyNet . NewSunny ()
func main () {
//绑定回调函数
Sunny . SetGoCallback ( HttpCallback , TcpCallback , WSCallback , UdpCallback )
//绑定端口号并启动
Sunny . SetPort ( 2023 ). Start ()
//避免程序退出
time . Sleep ( 24 * time . Hour )
}
func HttpCallback ( Conn SunnyNet. ConnHTTP ) {
if Conn . Type () == public . HttpSendRequest {
//fmt.Println(Conn.URL())
//发起请求
//直接响应,不让其发送请求
//Conn.StopRequest(200, "Hello Word")
} else if Conn . Type () == public . HttpResponseOK {
//请求完成
//log.Println("Call", Conn.URL())
} else if Conn . Type () == public . HttpRequestFail {
//请求错误
/* fmt.Println(Conn.Request.URL.String(), Conn.GetError())
*/
}
}
func WSCallback ( Conn SunnyNet. ConnWebSocket ) {
Conn . Context ()
//fmt.Println(Conn.Url)
}
func TcpCallback ( Conn SunnyNet. ConnTCP ) {
if Conn . Type () == public . SunnyNetMsgTypeTCPAboutToConnect {
//即将连接
mode := string ( Conn . Body ())
info . Println ( "PID" , Conn . PID (), "TCP 即将连接到:" , mode , Conn . LocalAddress (), "->" , Conn . RemoteAddress ())
//修改目标连接地址
//Conn.SetNewAddress("8.8.8.8:8080")
return
}
if Conn . Type () == public . SunnyNetMsgTypeTCPConnectOK {
info . Println ( "PID" , Conn . PID (), "TCP 连接到:" , Conn . LocalAddress (), "->" , Conn . RemoteAddress (), "成功" )
return
}
if Conn . Type () == public . SunnyNetMsgTypeTCPClose {
info . Println ( "PID" , Conn . PID (), "TCP 断开连接:" , Conn . LocalAddress (), "->" , Conn . RemoteAddress ())
return
}
if Conn . Type () == public . SunnyNetMsgTypeTCPClientSend {
info . Println ( "PID" , Conn . PID (), "发送数据" , Conn . LocalAddress (), Conn . RemoteAddress (), Conn . Type (), Conn . BodyLen (), Conn . Body ())
return
}
if Conn . Type () == public . SunnyNetMsgTypeTCPClientReceive {
info . Println ( "PID" , Conn . PID (), "收到数据" , Conn . LocalAddress (), Conn . RemoteAddress (), Conn . Type (), Conn . BodyLen (), Conn . Body ())
return
}
}
func UdpCallback ( Conn SunnyNet. ConnUDP ) {
if Conn . Type () == public . SunnyNetUDPTypeSend {
//客户端向服务器端发送数据
info . Println ( "PID" , Conn . PID (), "发送UDP" , Conn . LocalAddress (), Conn . RemoteAddress (), Conn . BodyLen ())
//修改发送的数据
//Conn.SetBody([]byte("Hello Word"))
return
}
if Conn . Type () == public . SunnyNetUDPTypeReceive {
//服务器端向客户端发送数据
info . Println ( "PID" , Conn . PID (), "接收UDP" , Conn . LocalAddress (), Conn . RemoteAddress (), Conn . BodyLen ())
//修改响应的数据
//Conn.SetBody([]byte("Hello Word"))
return
}
if Conn . Type () == public . SunnyNetUDPTypeClosed {
info . Println ( "PID" , Conn . PID (), "关闭UDP" , Conn . LocalAddress (), Conn . RemoteAddress ())
return
}
}