-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
186 lines (169 loc) · 4.88 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"time"
)
var ProxyApi = "http://thinklong.sinaapp.com/proxy.php?act=get&limit="
var ProxyDelApi = "http://thinklong.sinaapp.com/proxy.php?act=del&url="
var ProxyLogApi = "http://thinklong.sinaapp.com/executelog.php?host="
//安卓市场
//var Url = "http://apk.hiapk.com/Download.aspx?aid=1543012&rel=nofollow&module=256&info=41OLiFBORVw%3D"
//var Referer_url = "http://apk.hiapk.com/html/2013/06/1543012.html?module=256&info=41OLiFBORVw%3D"
//var Host = "apk.hiapk.com"
//应用宝
var Url = "http://android.myapp.com/android/down.jsp?appid=796684&icfa=-1&lmid=1022&g_f=0&actiondetail=0&softname=%E5%8F%A3%E8%A2%8B%E4%B9%90%E5%B1%85&downtype=1&transactionid=1375434227223079&topicid=-1&pkgid=-1"
var Referer_url = "http://android.myapp.com/android/appdetail.jsp?appid=796684&actiondetail=0&pageNo=1&clickpos=1&softname=%E5%8F%A3%E8%A2%8B%E4%B9%90%E5%B1%85&transactionid=1375434227223079&lmid=1022"
var Host = "android.myapp.com"
//var Url = "http://www.baidu.com/s?wd=ip"
//var Host = "www.baidu.com"
//var Referer_url = "http://www.baidu.com/s?wd=ip"
//var proxy_array []string
type http_pool struct {
Url string
//Referer_url string
Headers map[string]string
Method string
ProxyUrl string
Timeout int
// Sleep int
}
type ProxyList struct {
Id string
Url string
Host string
Port string
Time string
}
var ProxyData []json.RawMessage
var proxy_list ProxyList
func main() {
count := 2000
limit := fmt.Sprintf("%d", count)
ProxyApi += limit
//获取Proxy数据
httpx := Newhttppool(ProxyApi, "", "GET", "", 10)
proxy_data := httpx.http_send(1)
//proxy_array1 := make(map[string]string{})
//var proxy_array1 ProxyList
if err := json.Unmarshal([]byte(proxy_data), &ProxyData); err != nil {
log.Fatal(err.Error())
}
//proxy_array := make(map[int]string{})
for key, _ := range ProxyData {
json.Unmarshal(ProxyData[key], &proxy_list)
httpx := Newhttppool(Url, Referer_url, "GET", string(proxy_list.Url), 10)
httpx.http_send(0)
//fmt.Println(i)
time.Sleep(time.Duration(10) * time.Second)
}
//proxy_array = []string{"http://125.39.66.131:80/", "http://119.161.133.188:9000/"}
/*
for i := 0; i <= count; i++ {
httpx := Newhttppool(Url, Referer_url, "GET", proxy_array[i], 3)
httpx.http_send(0)
time.Sleep(time.Duration(10) * time.Second)
}
*/
}
func Newhttppool(url string, referer string, method string, proxyurl string, timeout int) (h *http_pool) {
headers := make(map[string]string)
headers["Referer"] = referer
headers["Host"] = Host
//headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
//headers["Accept-Encoding"] = "gzip,deflate,sdch"
//headers["Accept-Language"] = "zh-CN,zh;q=0.8"
//headers["Connection"] = "keep-alive"
headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36"
return &http_pool{
Url: url,
Headers: headers,
Method: method,
ProxyUrl: proxyurl,
Timeout: timeout,
}
}
func del_proxy(id string) {
url_ := ProxyDelApi + id
fmt.Println(url_)
httpx := Newhttppool(url_, "", "GET", "", 10)
httpx.http_send(1)
}
func execute_log(host string) {
log_url := ProxyLogApi + host
httpx := Newhttppool(log_url, "", "GET", "", 5)
httpx.http_send(1)
}
func (h *http_pool) http_send(is_content int) (html string) {
transport := &http.Transport{}
if len(h.ProxyUrl) > 0 {
transport = getTransportFieldURL(h.ProxyUrl)
}
//设置超时时间
//timeout
transport.Dial = func(netw, addr string) (net.Conn, error) {
deadline := time.Now().Add(2000 * time.Millisecond)
c, err := net.DialTimeout(netw, addr, time.Second)
if err != nil {
return nil, err
}
c.SetDeadline(deadline)
return c, nil
}
client := &http.Client{Transport: transport}
req, err := http.NewRequest(h.Method, h.Url, nil)
if err != nil {
log.Fatal(err.Error())
}
//headers
if len(h.Headers) > 0 {
for k, v := range h.Headers {
req.Header.Set(k, v)
}
}
resq, err := client.Do(req)
//defer resq.Body.Close()
if err != nil {
//log.Fatal(err.Error())
//log.Println(err.Error())
fmt.Println("请求失败!")
html = "false"
if len(h.ProxyUrl) > 0 {
del_proxy(string(proxy_list.Id))
fmt.Println(string(proxy_list.Id))
}
//resq.Body.Close()
return
}
if resq.StatusCode == 200 {
//html, _ = string(resq.Location())
if is_content == 1 {
robots, err := ioutil.ReadAll(resq.Body)
if err != nil {
log.Fatal(err.Error())
}
html = string(robots)
} else {
execute_log(h.Headers["Host"])
html += "true\n"
fmt.Println(html)
}
resq.Body.Close()
//
} else {
html = ""
}
return
}
//指定代理ip
func getTransportFieldURL(proxyurl string) (transport *http.Transport) {
url_i := url.URL{}
url_proxy, _ := url_i.Parse(proxyurl)
transport = &http.Transport{Proxy: http.ProxyURL(url_proxy)}
return
}