c# 批量获取zoomeye数据
2021-07-07 16:09
标签:des safari ons contains null nta x64 obj cup c# 批量获取zoomeye数据 标签:des safari ons contains null nta x64 obj cup 原文地址:https://www.cnblogs.com/had3s/p/9755048.html 1 using Newtonsoft.Json;
2 using Newtonsoft.Json.Linq;
3 using System;
4 using System.Collections.Generic;
5 using System.IO;
6 using System.Net;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace zoomeye测试
11 {
12 public partial class Form1 : Form
13 {
14 public Form1()
15 {
16 InitializeComponent();
17
18
19 }
20
21 private void button1_Click(object sender, EventArgs e)
22 {
23 //int page = Convert.ToInt32(numericUpDown1.Value);
24 int page = 100;
25
26
27
28
29
30 Liststring> end = GetIp(textBox2.Text, page, textBox3.Text, textBox1.Text);
31 dgv.Rows.Clear();
32 if (end != null)
33 {
34 for (int i = 0; i )
35 {
36 dgv.Rows.Add();
37 dgv.Rows[i].Cells["ip"].Value = end[i];//示范课名称
38
39 }
40 }
41
42 }
43
44
45 public static string Login(string param)
46 {
47
48 string strURL = "https://api.zoomeye.org/user/login";
49 System.Net.HttpWebRequest request;
50 request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
51 request.Method = "POST";
52 request.Host = "api.zoomeye.org";
53 string paraUrlCoded = param;
54 byte[] payload;
55 payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
56 request.ContentLength = payload.Length;
57 Stream writer = request.GetRequestStream();
58 writer.Write(payload, 0, payload.Length);
59 writer.Close();
60 System.Net.HttpWebResponse response;
61 response = (System.Net.HttpWebResponse)request.GetResponse();
62 System.IO.Stream s;
63 s = response.GetResponseStream();
64 string StrDate = "";
65 StreamReader Reader = new StreamReader(s, Encoding.UTF8);
66 StrDate = Reader.ReadToEnd();
67 JObject newObj1 = (JObject)JsonConvert.DeserializeObject(StrDate);
68 return newObj1["access_token"].ToString();
69 }
70
71 public Liststring> GetIp(string Authorization, int page, string key, string cookie)
72 {
73 try
74 {
75 Liststring> arr = new Liststring>();
76 for (int i = 1; i 1; i++)
77 // for (int i = 1; i
78 {
79
80
81 //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
82 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.zoomeye.org/api/search?q=" + key + "&p=" + i);
83 request.Host = "www.zoomeye.org";
84 request.Accept = "application/json, text/plain, */*";
85 //request.Headers.Add("Accept-Encoding", "gzip, deflate, br");
86 request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4");
87 request.Headers.Add("Cookie", cookie);
88 request.Headers.Add("If-None-Match", "W/\"2b164f5a281e50a2522a9ffebc789fde26850e0b\"");
89 request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36";
90 request.Headers.Add("Cube-Authorization", Authorization);
91 request.Referer = "https://www.zoomeye.org/searchResult?q=" + key + "&p=" + i;
92 //request.Connection = "Close";
93 HttpWebResponse response;
94 response = (HttpWebResponse)request.GetResponse();
95 Stream s;
96 s = response.GetResponseStream();
97 string encoding = response.ContentEncoding;
98 if (encoding == null || encoding.Length 1)
99 {
100 encoding = "UTF-8"; //默认编码
101 }
102 StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
103 string retString = reader.ReadToEnd();
104 JObject newObj1 = (JObject)JsonConvert.DeserializeObject(retString);
105 JArray jar = JArray.Parse(newObj1["matches"].ToString());
106 page = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(newObj1["total"].ToString()) / 20));
107 if (jar.Count != 0)
108 {
109 try
110 {
111 foreach (var item in jar)
112 {
113 string strValue = "";
114 int exis = 0;
115 strValue += "http://" + item["ip"];
116 strValue += ":" + item["portinfo"]["port"];
117
118 foreach (string items in arr)
119 {
120 if (items == strValue)
121 {
122 exis++;
123 }
124 }
125 if (exis == 0)
126 {
127 arr.Add(strValue);
128 }
129
130 }
131 }
132 catch (Exception)
133 {
134
135
136 }
137
138
139 }
140 numericUpDown1.Value = i;
141 progressBar(i);
142 WriteFile(arr);
143 System.Threading.Thread.Sleep(5000);
144
145 }
146 return arr;
147 }
148 catch (Exception ex)
149 {
150
151 MessageBox.Show("请检查cookie及Cube-Authorization有效性!");
152 return null;
153 }
154
155
156
157
158
159
160 }
161 public static void WriteFile(Liststring> arr)
162 {
163 StreamWriter sw = new StreamWriter("E:/fileZoomEye.txt", true, System.Text.Encoding.Default);
164 string strfromtxt = File.ReadAllText(@"E:/fileZoomEye - 副本.txt", Encoding.GetEncoding("GB2312"));
165 for (int i = 0; i )
166 {
167 if (strfromtxt.Contains(Convert.ToString(arr[i])))
168 {
169
170 }
171 else
172 {
173 sw.WriteLine("" + arr[i]);
174 }
175
176 }
177
178 sw.Close();
179 }
180
181 public void progressBar(int page)
182 {
183
184
185
186 if (progressBar1.Value + 100 / page > 100 || progressBar1.Value + 100 / page == 100)
187 {
188 progressBar1.Value = 100;
189 }
190 else
191 {
192 progressBar1.Value += 100 / page;
193 }
194 }
195
196
197 }
198 }