Comments (2)
麻烦贴下源代码
from go-curl.
curl.go
package main
import (
"bytes"
"errors"
curl "github.com/andelf/go-curl"
"net/url"
//"os"
"fmt"
//"time"
)
type Curlx struct {
Debug bool //调试开关
Url string
Headers map[string]string
ClientIp string //本机外网IP,可选
TargetIp string
ProxyUrl string //代理URL
PostData string
ConnectTimeout int //连接超时时间,秒
Result bytes.Buffer //保存结果
Err error //报错信息
}
func NewCurlx() (c *Curlx) {
headers := make(map[string]string)
headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36"
reqUrl := "http://localhost/"
return &Curlx{
Url: reqUrl,
Headers: headers,
ConnectTimeout: 10,
Err: nil,
Debug: false,
}
}
//设置url
func (c *Curlx) SetUrl(url string) {
c.Url = url
}
//设置连接超时时间
func (c *Curlx) SetConnectTimeout(second int) {
c.ConnectTimeout = second
}
//添加header
func (c *Curlx) AddHeader(key, value string) {
c.Headers[key] = value
}
//指定出口ip
func (c *Curlx) SetClientIp(ip string) {
c.ClientIp = ip
}
//指定目标ip
func (c *Curlx) SetTargetIp(ip string) {
c.TargetIp = ip
}
//打开调试模式
func (c *Curlx) SetDebug() {
c.Debug = true
}
//设置post数据
func (c *Curlx) SetPostString(data string) {
c.PostData = data
}
//转换header map为字符数组
func (c *Curlx) HeaderString() []string {
headers := []string{}
for k, v := range c.Headers {
headers = append(headers, k+": "+v)
}
return headers
}
//获取返回body
func (c *Curlx) GetBody() (body string, err error) {
body = c.Result.String()
err = c.Err
return
}
func (c *Curlx) Send() error {
c.Result.Reset()
easy := curl.EasyInit()
defer easy.Cleanup()
if easy != nil {
if c.Debug == true {
easy.Setopt(curl.OPT_VERBOSE, true)
}
if c.ClientIp != "" {
easy.Setopt(curl.OPT_INTERFACE, c.ClientIp)
}
if c.TargetIp != "" {
u, err := url.Parse(c.Url)
if err != nil {
c.Err = errors.New(err.Error() + " target ip is " + c.TargetIp)
return c.Err
}
RawQuery := ""
if u.RawQuery != "" {
RawQuery = "?" + u.RawQuery
}
c.Url = fmt.Sprintf("%s://%s%s%s", u.Scheme, c.TargetIp, u.Path, RawQuery)
c.AddHeader("Host", u.Host)
}
easy.Setopt(curl.OPT_URL, c.Url)
//easy.Setopt(curl.OPT_PORT, 7891)
easy.Setopt(curl.OPT_CONNECTTIMEOUT, c.ConnectTimeout)
easy.Setopt(curl.OPT_HTTPHEADER, c.HeaderString())
easy.Setopt(curl.OPT_WRITEFUNCTION, func(buf []byte, userdata interface{}) bool { c.Result.Write(buf); return true })
if c.PostData != "" {
easy.Setopt(curl.OPT_POSTFIELDS, c.PostData)
}
c.Err = easy.Perform()
}
return c.Err
}
/*
func main() {
c := NewCurlx()
c.Url = "http://www.baidu.com/"
c.ClientIp = "192.168.3.203"
//c.SetTargetIp("220.181.111.86")
c.SetPostString("a=b&c=d")
c.AddHeader("Referer", "localhost")
c.AddHeader("Accept", "text/html")
c.Send()
//c.Result.WriteTo(os.Stdout)
body, err := c.GetBody()
if err != nil {
fmt.Println("Error : ", err.Error())
} else {
fmt.Println(body)
}
}
*/
fastcc.go
...
for {
select {
case <-time.After(time.Duration(w.SleepTime) * time.Millisecond):
for uid = 0; uid < url_len; uid++ {
if w.Random == 0 {
surl = urls[uid]
} else {
i1 := int(float32(url_len) * rand.Float32())
surl = urls[i1]
}
surls := strings.Split(surl, " ")
if len(surls) > 1 {
surl = surls[0]
dial_host = strings.Trim(surls[1], " ")
} else {
u, _ := url.Parse(surl)
dial_host = u.Host
}
log.Debugf("%s", dial_host)
surl = replace_random_string(surl)
curlx := NewCurlx()
curlx.SetUrl(surl)
curlx.SetTargetIp(dial_host)
curlx.SetClientIp(w.LocalIp)
header := makeHeaderSlice()
for k, v := range header {
curlx.AddHeader(k, v)
}
curlx.Send()//这里是上面的132行
bodyString, err := curlx.GetBody()
...
在aws上运行,一下就崩溃了。出错信息同上。
from go-curl.
Related Issues (20)
- Perform() hangs when passing in false to WRITEFUNCTION HOT 10
- Issues when passing in multiple values to the OPT_HTTPHEADER HOT 2
- How store all Cookies in a file? HOT 1
- panic: runtime error: invalid memory address or nil pointer dereference
- 请求curl返回的各项时间为 0 HOT 1
- is curl_global_init handled safely? is the library thread-safe? HOT 6
- Couldn't read Getinfo Informations
- use C.struct, not _Ctype_struct
- Cannot compile after march 14 update HOT 9
- cannot find the PUT and GET method implementation
- Is there functionality for running the requests through torsockets?
- how to know the compiled in libcurl version?
- HTTP2 support?
- Get cURL error code HOT 1
- Problem in building go software for windows HOT 4
- Getting SSL certificate expiry date
- Windows: callback.go:8:10: fatal error: curl/curl.h: No such file or directory HOT 1
- curl 7.56 deprecations
- library not supporting curl version 8.0.X or higher
- Not building at Docker
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-curl.