-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
451 lines (216 loc) · 170 KB
/
search.xml
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>Git学习</title>
<link href="2022/02/24/learn-git/"/>
<url>2022/02/24/learn-git/</url>
<content type="html"><![CDATA[<h4 id="git-基本命令"><a href="#git-基本命令" class="headerlink" title="git 基本命令"></a>git 基本命令</h4><p><code>git init</code> 初始化仓库</p><p><code>git add <filename></code> 加入暂存区</p><p><code>git add .</code> 将所有文件加入暂存区</p><p><code>git commit -m <messeage> </code> 提交文件到本地仓库 <em>message为对该次提交的描述</em></p><p><code>git reset <filename> </code> 移出暂存区</p><p><code>alias</code> 别名</p><p>git安装目录 <code>gitconfig</code>文件可以设置alias</p><p><code>git reflog</code> 可查看commitID</p><p><code>git checkout -b <name> <template></code>创建新的分支 </p><p><code><name></code> 新分支的名字 <code><template></code>以哪个分支或者commit为模板 </p><p>不填则默认以当前分支为模板</p><p><code>git checkout <branchname></code>切换到指定分支</p><p><code>git branch</code> 查看所有分支</p><h4 id="git-回滚"><a href="#git-回滚" class="headerlink" title="git 回滚"></a>git 回滚</h4><p><code>git reset <commitID></code> 回退</p><p>1.已提交,没有push</p><ul><li><code>git reset --soft</code> 撤销<code>commit</code></li><li><code>git reset --mix</code>撤销commit和add两个动作</li></ul><p>2.已提交,并且push</p><ul><li><code>git reset --hard</code>撤销并舍弃版本号之后的提交记录,文件将还原为所选提交的状态</li><li><code>git revert</code> 文件还原为所选提交状态 本地变更保持不变</li></ul><p>文件状态:<br>1.没有被add过的文件叫untracked<br>2.add之后文件处于staged状态等待commit<br>3.commit之后文件处于unmodified这里之所以是modified是因为文件会跟仓库中的文件对比<br>4.当unmodified的文件被修改则会变为modified状态<br>5.modified之后的文件add之后将继续变为staged状态<br>6.unmodifed的文件还有一种可能是已经不再需要了,那么可以remove它不再追踪变为untracked状态</p><ul><li><input checked="" disabled="" type="checkbox"> git flow工作流</li><li><input checked="" disabled="" type="checkbox"> git rebase 和 merge (合并和变基)</li></ul>]]></content>
<tags>
<tag> git </tag>
</tags>
</entry>
<entry>
<title>C++基础</title>
<link href="2021/12/01/cplus/"/>
<url>2021/12/01/cplus/</url>
<content type="html"><![CDATA[<h3 id="头文件写法"><a href="#头文件写法" class="headerlink" title="头文件写法"></a>头文件写法</h3><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">#防卫式声明#ifndef _COMPLEX_ //如果没有定义这个‘_COMPLEX_’ #define _COMPLEX_ //如果没有定义这个‘_COMPLEX_’ ,则定义这个‘_COMPLEX_’//第一次include 就会定义这个_COMPLEX_//第二次再include时,这个_COMPLEX_被定义过了,不会进入到主体,也就不会重复include······ #endif<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>自己写的头文件用<code>#include “name”</code> 即用双引号引用</p><h3 id="类模板"><a href="#类模板" class="headerlink" title="类模板"></a>类模板</h3><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20211103213406959.png"></p><p>如果是这样 那么<code>re,im</code>就被写死了,这好吗?这不好。</p><p>如果需要一个float类型或者整型类型的话难到要重新写一个类吗?</p><p>这时候就用到类模板,不把变量类型写死</p><p> 所以这样</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20211103214052692.png" alt="注意黄字部分"></p><p>那么我们使用时只需这样</p><p><code>complex<double> c1(2.5,1.5)</code> <code>re,im</code>就是<code>double</code>型</p><p><code>complex<int> c2(2,6)</code> <code>re,im</code>就是<code>int</code>型</p><h3 id="inline(内联)函数"><a href="#inline(内联)函数" class="headerlink" title="inline(内联)函数"></a>inline(内联)函数</h3><ul><li><p>定义 </p><ul><li>定义在class里的函数</li></ul></li><li><p>优点</p><ul><li>速度快</li><li>有宏的特性,没有宏的缺点</li></ul></li><li><p>缺点</p><ul><li>过于复杂的inline func不会被编译器定义成inline</li></ul></li></ul><h3 id="构造函数"><a href="#构造函数" class="headerlink" title="构造函数"></a>构造函数</h3><ul><li>特别之处<ul><li>函数名称和类的名称相同</li><li>没有返回类型,也不需要有</li><li>构造函数就是用来创建对象的</li><li>创建对象时构造函数会被自然而然调用起来</li><li>初值列(见图) 要好好利用 (构造函数的特殊语法)</li></ul></li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20211103221805093.png" alt="初值列"></p><h3 id="参数传递"><a href="#参数传递" class="headerlink" title="参数传递"></a>参数传递</h3><ul><li>尽量用引用 <ul><li>如果不想传进去的参数被修改,加<code>const</code></li></ul></li></ul><h3 id="友元(friends)"><a href="#友元(friends)" class="headerlink" title="友元(friends)"></a>友元(friends)</h3><ul><li>友元可以调用Private</li><li>相同的class互为友元</li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20211103233743036.png" alt="image-20211103233743036"></p><p><code>c2</code>通过<code>func</code>直接访问<code>c1</code>的<code>re im</code></p><h3 id="成员函数"><a href="#成员函数" class="headerlink" title="成员函数"></a>成员函数</h3><ul><li>任何一个成员函数都有一个隐藏的this指针</li><li>this指针指向这个调用者 ,即谁调用,指向谁</li></ul>]]></content>
<categories>
<category> C语言 </category>
</categories>
<tags>
<tag> C++ </tag>
</tags>
</entry>
<entry>
<title>Padavan常用命令</title>
<link href="2021/12/01/padavan/"/>
<url>2021/12/01/padavan/</url>
<content type="html"><![CDATA[<h2 id="重启服务命令"><a href="#重启服务命令" class="headerlink" title="重启服务命令"></a>重启服务命令</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">restart_dhcpd restart_firewall restart_virtualvpn_client restart_wanrestart_dns restart_networkmap restart_virtualvpn_server2G相关的命令radio2_disable radio2_enable radio2_guest_enable radio2_toggle radio2_toggle_onradio2_eeprom_mac radio2_guest_disable radio2_restart radio2_toggle_off5G相关的命令radio5_disable radio5_enable radio5_guest_enable radio5_toggle radio5_toggle_onradio5_eeprom_mac radio5_guest_disable radio5_restart radio5_toggle_off<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p> 配合计划任务,就可以定时重启各种服务了</p><h2 id="NVRAM"><a href="#NVRAM" class="headerlink" title="NVRAM"></a>NVRAM</h2><p><code>nvram show</code><br>列出 <code>NVRAM</code> 内所有参数,我们亦可以用 <code>grep</code> 命令来筛选</p><p>这命令列出了所以用 <code>lan</code>开头的参数</p><p><code>nvram show | grep lan</code></p><p><code>nvram set</code> 参数=数值</p><p><code>nvram set vpnc_dgw=1</code></p><h2 id="自定义脚本"><a href="#自定义脚本" class="headerlink" title="自定义脚本"></a>自定义脚本</h2><h3 id="1-检测全部流量是否走VPN"><a href="#1-检测全部流量是否走VPN" class="headerlink" title="1.检测全部流量是否走VPN"></a>1.检测全部流量是否走VPN</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/sh</span><span class="token assign-left variable">vpnc_dwg_status</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span>nvram get vpnc_dgw<span class="token variable">`</span></span>logger -t <span class="token string">"【check_vpn】"</span> <span class="token string">"检测是否全部流量走VPN"</span><span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$vpnc_dwg_status</span>"</span> <span class="token operator">==</span> <span class="token string">"1"</span> <span class="token punctuation">]</span> <span class="token punctuation">;</span> <span class="token keyword">then</span>logger -t <span class="token string">"【check_vpn】"</span> <span class="token string">"全局流量走VPN"</span><span class="token keyword">else</span>logger -t <span class="token string">"【check_vpn】"</span> <span class="token string">"快断网了!自动设置全局流量走VPN"</span>nvram <span class="token builtin class-name">set</span> <span class="token assign-left variable">vpnc_dgw</span><span class="token operator">=</span><span class="token number">1</span>restart_vpn_client<span class="token keyword">fi</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="2-检测桥接状态"><a href="#2-检测桥接状态" class="headerlink" title="2.检测桥接状态"></a>2.检测桥接状态</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/sh</span><span class="token assign-left variable">ping_text</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">ping</span> -4 <span class="token number">10.0</span>.1.1 -c <span class="token number">1</span> -w <span class="token number">4</span> -q<span class="token variable">`</span></span><span class="token assign-left variable">ping_time</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">echo</span> $ping_text <span class="token operator">|</span> <span class="token function">awk</span> -F <span class="token string">'/'</span> <span class="token string">'{print <span class="token variable">$4</span>}'</span><span class="token operator">|</span> <span class="token function">awk</span> -F <span class="token string">'.'</span> <span class="token string">'{print <span class="token variable">$1</span>}'</span><span class="token variable">`</span></span><span class="token assign-left variable">ping_loss</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">echo</span> $ping_text <span class="token operator">|</span> <span class="token function">awk</span> -F <span class="token string">', '</span> <span class="token string">'{print <span class="token variable">$3</span>}'</span> <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print <span class="token variable">$1</span>}'</span><span class="token variable">`</span></span><span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token operator">!</span> -z <span class="token string">"<span class="token variable">$ping_time</span>"</span> <span class="token punctuation">]</span> <span class="token punctuation">;</span> <span class="token keyword">then</span><span class="token builtin class-name">echo</span> <span class="token string">"online"</span>logger -t <span class="token string">"【wtach_wan】"</span> <span class="token string">"网络连接正常"</span><span class="token keyword">else</span><span class="token builtin class-name">echo</span> <span class="token string">"Internet互联网断线后自动重启WAN"</span>logger -t <span class="token string">"【wtach_wan】"</span> <span class="token string">"Internet互联网断线后自动重启WAN"</span>restart_wan<span class="token keyword">fi</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<categories>
<category> 网络 </category>
</categories>
<tags>
<tag> Padavan </tag>
</tags>
</entry>
<entry>
<title>SQL注入基础</title>
<link href="2021/12/01/sql-zhu-ru-ji-chu/"/>
<url>2021/12/01/sql-zhu-ru-ji-chu/</url>
<content type="html"><![CDATA[<p>查库 <code>select schema_name from information_schema.schemata</code></p><p>查表 <code>select table_name from information_schema.tables where table_schema=''</code></p><p>查列 <code>select column_name from information_schema.columns where table_name =''</code></p><p>查字段 <code>select username,password from security.users;</code></p><h3 id="LIMIT"><a href="#LIMIT" class="headerlink" title="LIMIT"></a>LIMIT</h3><p><code>select * from users where id='1' limit 0,1</code>//执行该语句前需要先选择对应的数据库</p><p>limit 0,1 其中 0表示从哪开始,1表示步长</p><h3 id="order"><a href="#order" class="headerlink" title="order"></a>order</h3><p><code>select * from users order by 1</code> //对users这个表中的第一列进行排序,如果不存在这一列则会报错,可以利用这一点获得列数</p><h3 id="union-联合查询"><a href="#union-联合查询" class="headerlink" title="union 联合查询"></a>union 联合查询</h3><p>应用场景:<br>要查询的结果来自于多个表,且多个表没有直接的连接关系,但查询的信息一致时 </p><p>特点:<br>1、要求多条查询语句的查询<strong>列数是一致的</strong>!<br>2、要求多条查询语句的查询的每一列的类型和顺序最好一致<br>3、union关键字默认去重,如果使用union all 可以包含重复项</p><h4 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h4><p>对 <code>http://localhost:8888/Less-1/?id=-1' union select 1,2,3--+ </code></p><p>执行的mysql语句为</p><pre class="line-numbers language-mysql" data-language="mysql"><code class="language-mysql">SELECT * FROM users WHERE id='-1' union select 1,2,3-- ' LIMIT 0,1<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h3 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h3><h4 id="group-concat"><a href="#group-concat" class="headerlink" title="group_concat()"></a>group_concat()</h4><h4 id="concat-ws-‘-’-A-B"><a href="#concat-ws-‘-’-A-B" class="headerlink" title="concat_ws(‘~’,A,B)"></a>concat_ws(‘~’,A,B)</h4><blockquote><p>注意这里的单引号,我们要尽量避免出现单引号问题,改用十六进制</p></blockquote><p>三个参数分别为 分隔符 数据A 数据B</p><p>最终返回结果为 A~B</p><h4 id="left-a-b"><a href="#left-a-b" class="headerlink" title="left(a,b)"></a>left(a,b)</h4><p>•left(a,b)从左侧截取a的前b位,正确则返回1,错误则返回0</p><p><code>left(database(),1)='s'</code> //第一位是否为s</p><h4 id="regexp"><a href="#regexp" class="headerlink" title="regexp()"></a>regexp()</h4><p><code>select user() regexp 'r'</code></p><p>结果是r开头的用户名,root等,regexp后面带正则表达式</p><h4 id="like"><a href="#like" class="headerlink" title="like()"></a>like()</h4><p><code>select user() like like 'ro%'</code> 此处的作用为匹配 开头为“ro”的用户名</p><h4 id="substr-a-b-c"><a href="#substr-a-b-c" class="headerlink" title="substr(a,b,c)"></a>substr(a,b,c)</h4><p>从位置b开始,截取a字符串c位长度</p><pre class="line-numbers language-mysql" data-language="mysql"><code class="language-mysql">select substr((select database()),1,1)='s’; -- 匹配第一个字符是否是 sselect substr((select database()),1,3)= ‘sec’; -- 匹配前三个个字符是否是 sec<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><h4 id="ascii"><a href="#ascii" class="headerlink" title="ascii()"></a>ascii()</h4><p> 将某个字符串转化为ascii值 </p>]]></content>
<categories>
<category> SQL </category>
</categories>
<tags>
<tag> SQL注入 </tag>
</tags>
</entry>
<entry>
<title>Python基础巩固</title>
<link href="2021/12/01/python-ji-chu-gong-gu/"/>
<url>2021/12/01/python-ji-chu-gong-gu/</url>
<content type="html"><![CDATA[<h3 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h3><ul><li>首字符是字母或下划线</li><li>其余可以是<strong>字母、下划线、数字</strong></li><li>大小写敏感(PI和pi是不同的标识符)</li><li><strong>关键字</strong> <strong>不</strong> 可作为标识符</li></ul><p>关键字:</p><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> keyword<span class="token keyword">print</span><span class="token punctuation">(</span>keyword<span class="token punctuation">.</span>kwlist<span class="token punctuation">)</span><span class="token comment">#输出:</span><span class="token punctuation">[</span><span class="token string">'False'</span><span class="token punctuation">,</span> <span class="token string">'None'</span><span class="token punctuation">,</span> <span class="token string">'True'</span><span class="token punctuation">,</span> <span class="token string">'and'</span><span class="token punctuation">,</span> <span class="token string">'as'</span><span class="token punctuation">,</span> <span class="token string">'assert'</span><span class="token punctuation">,</span> <span class="token string">'async'</span><span class="token punctuation">,</span> <span class="token string">'await'</span><span class="token punctuation">,</span> <span class="token string">'break'</span><span class="token punctuation">,</span> <span class="token string">'class'</span><span class="token punctuation">,</span> <span class="token string">'continue'</span><span class="token punctuation">,</span> <span class="token string">'def'</span><span class="token punctuation">,</span> <span class="token string">'del'</span><span class="token punctuation">,</span> <span class="token string">'elif'</span><span class="token punctuation">,</span> <span class="token string">'else'</span><span class="token punctuation">,</span> <span class="token string">'except'</span><span class="token punctuation">,</span> <span class="token string">'finally'</span><span class="token punctuation">,</span> <span class="token string">'for'</span><span class="token punctuation">,</span> <span class="token string">'from'</span><span class="token punctuation">,</span> <span class="token string">'global'</span><span class="token punctuation">,</span> <span class="token string">'if'</span><span class="token punctuation">,</span> <span class="token string">'import'</span><span class="token punctuation">,</span> <span class="token string">'in'</span><span class="token punctuation">,</span> <span class="token string">'is'</span><span class="token punctuation">,</span> <span class="token string">'lambda'</span><span class="token punctuation">,</span> <span class="token string">'nonlocal'</span><span class="token punctuation">,</span> <span class="token string">'not'</span><span class="token punctuation">,</span> <span class="token string">'or'</span><span class="token punctuation">,</span> <span class="token string">'pass'</span><span class="token punctuation">,</span> <span class="token string">'raise'</span><span class="token punctuation">,</span> <span class="token string">'return'</span><span class="token punctuation">,</span> <span class="token string">'try'</span><span class="token punctuation">,</span> <span class="token string">'while'</span><span class="token punctuation">,</span> <span class="token string">'with'</span><span class="token punctuation">,</span> <span class="token string">'yield'</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><h3 id="表达式"><a href="#表达式" class="headerlink" title="表达式"></a>表达式</h3><p>用运算符(<strong>除了赋值运算符</strong>)连接各种类型数据的式子就是表达式</p><ul><li>运算符有优先级顺序</li><li>表达式必须有运算结果</li><li>单个常量或变量可以看作是最简单的表达式 例如:3,‘a’</li></ul><h3 id="数字"><a href="#数字" class="headerlink" title="数字"></a>数字</h3><ul><li>Python支持任意大的数字,具体可以大到什么程度仅受内存大小的限制。</li><li>由于精度的问题,对于实数运算可能会有一定的误差,<strong>应尽量避免在实数之间直接进行相等性测试</strong>,而是应该以二者之差的绝对值是否<strong>足够小</strong>作为两个实数是否相等的依据。</li><li>在数字的算术运算表达式求值时会进行隐式的类型转换</li></ul><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token operator">>></span><span class="token operator">></span> <span class="token number">0.4</span> <span class="token operator">-</span> <span class="token number">0.1</span> <span class="token operator">==</span> <span class="token number">0.3</span> <span class="token comment">#应尽量避免直接比较两个实数是否相等</span><span class="token boolean">False</span><span class="token operator">>></span><span class="token operator">></span> <span class="token builtin">abs</span><span class="token punctuation">(</span><span class="token number">0.4</span><span class="token operator">-</span><span class="token number">0.1</span> <span class="token operator">-</span> <span class="token number">0.3</span><span class="token punctuation">)</span> <span class="token operator"><</span> <span class="token number">1e</span><span class="token operator">-</span><span class="token number">6</span> <span class="token comment">#这里1e-6表示10的-6次方</span><span class="token boolean">True</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><h3 id="切片"><a href="#切片" class="headerlink" title="切片"></a>切片</h3><p>[N,M] 不包括M</p><pre class="line-numbers language-python" data-language="python"><code class="language-python">k表示步进,缺省为<span class="token number">1</span>当k<span class="token operator"><</span><span class="token number">0</span>时,a<span class="token punctuation">[</span>i<span class="token punctuation">,</span>j<span class="token punctuation">,</span>k<span class="token punctuation">]</span>表示从a<span class="token punctuation">[</span>i<span class="token punctuation">]</span>开始<span class="token punctuation">(</span>含a<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>到a<span class="token punctuation">[</span>j<span class="token punctuation">]</span>结束<span class="token punctuation">(</span>不含a<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span>,且顺序是从后向前进行遍历,返回遍历结果。i缺省时,默认为<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">.</span> j缺省时,默认为<span class="token operator">-</span><span class="token builtin">len</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span>当k<span class="token operator">></span><span class="token number">0</span>时,a<span class="token punctuation">[</span>i<span class="token punctuation">,</span>j<span class="token punctuation">,</span>k<span class="token punctuation">]</span>表示从a<span class="token punctuation">[</span>i<span class="token punctuation">]</span>开始<span class="token punctuation">(</span>含a<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>到a<span class="token punctuation">[</span>j<span class="token punctuation">]</span>结束<span class="token punctuation">(</span>不含a<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span>,且顺序是从前向后进行遍历,返回遍历结果。当i缺省时,默认为<span class="token number">0</span>当j缺省时,默认为<span class="token builtin">len</span><span class="token punctuation">(</span>alist<span class="token punctuation">)</span>k的正负值的改变只是改变了遍历的方向而已<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="赋值语句"><a href="#赋值语句" class="headerlink" title="赋值语句"></a>赋值语句</h3><p><code>a,b = b,a</code> 可以实现a和b的值互换</p><p>同样<code>a,b ,c= c,b,a</code>也是可以的</p><h3 id="Round"><a href="#Round" class="headerlink" title="Round"></a>Round</h3><p>返回浮点数的四舍五入值</p><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token keyword">in</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token boolean">False</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token keyword">in</span> <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token boolean">True</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20211106221358354.png"></p><h3 id="区间"><a href="#区间" class="headerlink" title="区间"></a>区间</h3><ul><li>range 左开右闭</li></ul><p>字符串 不可变类型</p><p>#考的是多分支情况下,执行第一个满足条件的代码,然后就跳出了,而不会顺序执行后续的每个分支</p><p>惰性求值</p><p>reversed zip map filter enumerate 都具有惰性求值</p><p>strip()函数注意的地方</p><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token builtin">str</span><span class="token operator">=</span>”<span class="token operator">**</span><span class="token operator">*</span>python<span class="token operator">**</span><span class="token operator">*</span>”<span class="token builtin">str</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span>‘<span class="token operator">*</span>’<span class="token punctuation">)</span>‘python’<span class="token comment">#会把首尾重复的都删除掉</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p>理解 append 与 extend 方法的区别</p><p>append 表示把某个数据当作新元素追加到列表的最后面,它的参数可以是<strong>任意对象</strong>:</p><p>extend 的参数必须是<strong>可迭代对象</strong>,表示把该对象里面所有元素<strong>逐个</strong>地追加到列表的后面。</p><h3 id="深拷贝-浅拷贝"><a href="#深拷贝-浅拷贝" class="headerlink" title="深拷贝 浅拷贝"></a>深拷贝 浅拷贝</h3><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> copyList <span class="token operator">=</span> <span class="token punctuation">[</span>“张三”<span class="token punctuation">,</span>”李四”<span class="token punctuation">,</span><span class="token punctuation">[</span>”大王五”<span class="token punctuation">,</span>”小王五”<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token comment">#等号:列表对象地址的拷贝,并没有实现拷贝数据</span>List1 <span class="token operator">=</span> List<span class="token comment">#浅拷贝:拷贝最外层的数据,嵌套的结构依然是地址引用</span>List2 <span class="token operator">=</span> List<span class="token punctuation">.</span>copy<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token comment">#深拷贝:拷贝数据</span>List3<span class="token operator">=</span>copy<span class="token punctuation">.</span>deepcopy<span class="token punctuation">(</span>List<span class="token punctuation">)</span><span class="token keyword">print</span><span class="token punctuation">(</span>“List<span class="token punctuation">:</span>”<span class="token punctuation">,</span>List<span class="token punctuation">)</span><span class="token keyword">print</span><span class="token punctuation">(</span>“等号<span class="token punctuation">:</span>”<span class="token punctuation">,</span>List1<span class="token punctuation">)</span><span class="token keyword">print</span><span class="token punctuation">(</span>“浅拷贝<span class="token punctuation">:</span>”<span class="token punctuation">,</span>List2<span class="token punctuation">)</span><span class="token keyword">print</span><span class="token punctuation">(</span>“深拷贝<span class="token punctuation">:</span>”<span class="token punctuation">,</span>List3<span class="token punctuation">)</span>输出结果:List<span class="token punctuation">:</span><span class="token punctuation">[</span><span class="token string">'张三'</span><span class="token punctuation">,</span> <span class="token string">'李四'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'大王五'</span><span class="token punctuation">,</span> <span class="token string">'小王五'</span><span class="token punctuation">]</span><span class="token punctuation">]</span>等号<span class="token punctuation">:</span><span class="token punctuation">[</span><span class="token string">'张三'</span><span class="token punctuation">,</span> <span class="token string">'李四'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'大王五'</span><span class="token punctuation">,</span> <span class="token string">'小王五'</span><span class="token punctuation">]</span><span class="token punctuation">]</span>浅拷贝<span class="token punctuation">:</span><span class="token punctuation">[</span><span class="token string">'张三'</span><span class="token punctuation">,</span> <span class="token string">'李四'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'大王五'</span><span class="token punctuation">,</span> <span class="token string">'小王五'</span><span class="token punctuation">]</span><span class="token punctuation">]</span>深拷贝<span class="token punctuation">:</span><span class="token punctuation">[</span><span class="token string">'张三'</span><span class="token punctuation">,</span> <span class="token string">'李四'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'大王五'</span><span class="token punctuation">,</span> <span class="token string">'小王五'</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="如何对列表进行排序"><a href="#如何对列表进行排序" class="headerlink" title="如何对列表进行排序"></a>如何对列表进行排序</h3><p>列表排序有两种方式,一种是列表自带的方法sort(),注意:sort()是原地操作;一种是内建函数<code>sorted()</code>,<strong>返回新的列表</strong>。复杂的数据类型可通过指定key参数进行排序。</p><p>remove 移除某个元素,而且只能移除第一次出现的元素。</p><p>del关键字 根据指定的位置移除某元素;</p><p> pop 方法可以返回移除的元素</p><p>tuple没有append()、insert()方法,也不能赋值成另外的元素,其他获取方法和list是一样的。<br>因为tuple不可变,所以代码更安全,如有可能,尽量使用tuple代替list。</p><h3 id="字典"><a href="#字典" class="headerlink" title="字典"></a>字典</h3><p>字典的迭代,dic.items()可查看字典的每一对键值对,注意:如果直接对字典对象进行迭<br>代或者遍历时默认是遍历字典的“键”:</p><p>使用 dic.clear()方法删除字典</p><p>aStock = {} 只删除了引用,并没有清空字典</p><h3 id="集合"><a href="#集合" class="headerlink" title="集合"></a>集合</h3><p>如果原序列或可迭代对象中有可变(不可哈希)的值,无法转换成为集合,抛出异常</p><h4 id="增加集合元素"><a href="#增加集合元素" class="headerlink" title="增加集合元素"></a>增加集合元素</h4><p>集合对象的 add()方法可以增加新元素,如果该元素已存在则忽略该操作,不会抛出异常;<br>update()方法合并另外一个集合中的元素到当前集合中,并自动去除重复元素。</p><p>集合具有无序性,只能随机删,不能指定索引</p><p>.join返回的是str</p><p>.join接收的也只能是str类型</p><p><code>()</code>元组</p><p><code>[ ]</code>列表</p><p><code>{ }</code>字典</p><p><code>index(,start,end)</code></p><p>字典<code>.get( ,default)</code> 若不存在 返回默认值 </p>]]></content>
<categories>
<category> Python </category>
</categories>
<tags>
<tag> Python </tag>
</tags>
</entry>
<entry>
<title>ALL IN ONE主机折腾日记</title>
<link href="2021/09/01/all-in-one-zhu-ji-zhe-teng-ri-ji/"/>
<url>2021/09/01/all-in-one-zhu-ji-zhe-teng-ri-ji/</url>
<content type="html"><![CDATA[<h2 id="效果图"><a href="#效果图" class="headerlink" title="效果图"></a>效果图</h2><h3 id="网络拓扑"><a href="#网络拓扑" class="headerlink" title="网络拓扑"></a>网络拓扑</h3><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6.png" alt="网络拓扑"></p><h3 id="ESXI网络拓扑"><a href="#ESXI网络拓扑" class="headerlink" title="ESXI网络拓扑"></a>ESXI网络拓扑</h3><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901104358832.png"></p><h3 id="iKuai"><a href="#iKuai" class="headerlink" title="iKuai"></a>iKuai</h3><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901104450931.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901104509316.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901104540125.png"></p><h3 id="LEDE"><a href="#LEDE" class="headerlink" title="LEDE"></a>LEDE</h3><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901104632029.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901104659181.png"></p><h3 id="实物图"><a href="#实物图" class="headerlink" title="实物图"></a>实物图</h3><p>图吧大佬狂喜</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901104949779.png"></p><h2 id="iKuai分流"><a href="#iKuai分流" class="headerlink" title="iKuai分流"></a>iKuai分流</h2><ol><li><p>下载文件(<a href="https://raw.githubusercontent.com/hq450/fancyss/master/rules/gfwlist.conf%EF%BC%89">https://raw.githubusercontent.com/hq450/fancyss/master/rules/gfwlist.conf)</a></p></li><li><p>使用Python 将GFwlist转化为iKuai可识别的格式</p></li><li><p>在iKuai域名分流里 导入生成的stream.txt文件</p><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment">#设置区域开始</span>wanname <span class="token operator">=</span> <span class="token string">'wan2'</span> <span class="token comment">#设置出国分流wan口名字</span><span class="token comment">#设置区域结束</span><span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'gfwlist.conf'</span><span class="token punctuation">,</span><span class="token string">'r'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span> gfwlist_txt <span class="token operator">=</span> f<span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span>pos1 <span class="token operator">=</span> <span class="token number">0</span>pos2 <span class="token operator">=</span> <span class="token number">0</span>data <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span> pos1 <span class="token operator">=</span> gfwlist_txt<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token string">'ipset=/.'</span><span class="token punctuation">,</span> pos2<span class="token punctuation">)</span> <span class="token keyword">if</span> pos1 <span class="token operator">==</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">:</span> <span class="token keyword">break</span> pos2 <span class="token operator">=</span> gfwlist_txt<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token string">'/gfwlist'</span><span class="token punctuation">,</span> pos1<span class="token punctuation">)</span> data<span class="token punctuation">.</span>append<span class="token punctuation">(</span>gfwlist_txt<span class="token punctuation">[</span>pos1<span class="token operator">+</span><span class="token number">8</span><span class="token punctuation">:</span>pos2<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token keyword">print</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>write <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">for</span> i <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span> writedata <span class="token operator">=</span> <span class="token string">'id='</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">" "</span><span class="token operator">+</span><span class="token string">'enabled=yes comment='</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">' domain='</span> <span class="token keyword">for</span> ii <span class="token keyword">in</span> data<span class="token punctuation">[</span><span class="token number">500</span><span class="token operator">*</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token number">500</span><span class="token operator">*</span><span class="token punctuation">(</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">:</span> writedata <span class="token operator">=</span> writedata<span class="token operator">+</span>ii<span class="token operator">+</span><span class="token string">','</span> writedata <span class="token operator">=</span> writedata<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token builtin">len</span><span class="token punctuation">(</span>writedata<span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span> writedata <span class="token operator">=</span> writedata<span class="token operator">+</span><span class="token string">' interface='</span><span class="token operator">+</span>wanname<span class="token operator">+</span><span class="token string">' src_addr= week=1234567 time=00:00-23:59'</span> write<span class="token punctuation">.</span>append<span class="token punctuation">(</span>writedata<span class="token punctuation">)</span><span class="token keyword">if</span> <span class="token builtin">len</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token operator">//</span><span class="token number">500</span> <span class="token operator">!=</span><span class="token number">0</span><span class="token punctuation">:</span> writedata <span class="token operator">=</span> <span class="token string">'id='</span> <span class="token operator">+</span> <span class="token builtin">str</span><span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">" "</span> <span class="token operator">+</span> <span class="token string">'enabled=yes comment='</span> <span class="token operator">+</span> <span class="token builtin">str</span><span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">' domain='</span> <span class="token keyword">for</span> ii <span class="token keyword">in</span> data<span class="token punctuation">[</span><span class="token number">500</span> <span class="token operator">*</span> <span class="token punctuation">(</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token punctuation">:</span> writedata <span class="token operator">=</span> writedata <span class="token operator">+</span> ii <span class="token operator">+</span> <span class="token string">','</span> writedata <span class="token operator">=</span> writedata<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token builtin">len</span><span class="token punctuation">(</span>writedata<span class="token punctuation">)</span> <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">]</span> writedata <span class="token operator">=</span> writedata <span class="token operator">+</span> <span class="token string">' interface='</span><span class="token operator">+</span>wanname<span class="token operator">+</span><span class="token string">' src_addr= week=1234567 time=00:00-23:59'</span> write<span class="token punctuation">.</span>append<span class="token punctuation">(</span>writedata<span class="token punctuation">)</span>finaldata <span class="token operator">=</span> <span class="token string">''</span><span class="token keyword">for</span> i <span class="token keyword">in</span> write<span class="token punctuation">:</span> finaldata <span class="token operator">=</span> finaldata<span class="token operator">+</span>i <span class="token operator">+</span><span class="token string">'\n'</span><span class="token keyword">print</span><span class="token punctuation">(</span>finaldata<span class="token punctuation">)</span><span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'stream.txt'</span><span class="token punctuation">,</span><span class="token string">'w'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span> f<span class="token punctuation">.</span>write<span class="token punctuation">(</span>finaldata<span class="token punctuation">)</span> <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="测个速"><a href="#测个速" class="headerlink" title="测个速"></a>测个速</h3><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901105948342.png"></p></li></ol><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901110014221.png"></p><p>实际使用也是 4k无压力</p><h2 id="NAS群晖应用"><a href="#NAS群晖应用" class="headerlink" title="NAS群晖应用"></a>NAS群晖应用</h2><h3 id="监控-Surveillance"><a href="#监控-Surveillance" class="headerlink" title="监控:Surveillance"></a>监控:Surveillance</h3><p>家里的萤石云原生支持RSTP串流,和贴吧大佬40个摄像头许可的Surveillance 配合,虽然不是很完美,但是比之前方便太多,尤其是Surveillance的智能延时确实不错</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210901110621692.png"></p><h2 id="ESXI安装"><a href="#ESXI安装" class="headerlink" title="ESXI安装"></a>ESXI安装</h2><h3 id="网卡驱动注入"><a href="#网卡驱动注入" class="headerlink" title="网卡驱动注入"></a>网卡驱动注入</h3><p>我的主板网卡是8168 默认不支持 ,因此需要下载<a href="https://vibsdepot.v-front.de/wiki/index.php/Net55-r8168">net55-r8168</a>这个驱动并封装</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/20210831232838.png"></p><p>驱动安装参考博客 <a href="https://blog.whsir.com/post-3377.html">https://blog.whsir.com/post-3377.html</a></p><p>ESXI参考博客 <a href="https://blog.csdn.net/huaidan1469/article/details/100032963">https://blog.csdn.net/huaidan1469/article/details/100032963</a></p><h3 id="ESXI管理地址外网访问"><a href="#ESXI管理地址外网访问" class="headerlink" title="ESXI管理地址外网访问"></a>ESXI管理地址外网访问</h3><p>转发到443端口,其他均无效</p><p>尝试修改默认端口,但ESXI每次重启后防火墙会重置,修改起来太繁琐。</p><h2 id="NAS群晖安装"><a href="#NAS群晖安装" class="headerlink" title="NAS群晖安装"></a>NAS群晖安装</h2><p>黑群晖的安装文件分为两个,第一部分为引导项,第二部分为系统镜像。每个版本的引导项支持的群晖系统版本有限,较低版本的引导项可能无法引导较新的系统镜像,导致无法进入系统,所以在选择引导盘时需要注意其是否支持你准备安装的群晖版本。你可以在 <a href="https://xpenology.com/forum/topic/12952-dsm-62-loader/">Jun 大的帖子</a>中获取到所有的引导项下载链接。</p><p>黑群晖和黑苹果的启动方式有点像,启动时会先启动引导,从引导里面读取信息,进而启动对应配置的系统,所以引导和系统是分开的。</p><p>因为引导文件是img格式的镜像文件,无法直接在ESXi上使用。有两种思路,第一种是将synoboot.img转换成iso文件,然后挂到虚拟机的光驱上,开机先启动光驱;另一种是将synoboot.img转换成ESXi的一块虚拟磁盘,这块盘是独立于数据盘的,开机先启动这块装有引导的磁盘。</p><p>首先安装转换引导文件的软件StarWind V2V Converter,<a href="https://www.starwindsoftware.com/download-starwind-products#download">官方下载地址</a></p><p>由于是要给ESXi用,所以选择VMDK,ESXi Server image</p><p>转换成功后得到的两个文件。稍后会将此上传</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/c4ca4238a0b923820dcc.jpg" alt="1"></p><p>1.新建虚拟机</p><p><a href="https://www.bokezhu.com/content/uploads/2019/07/c81e728d9d4c2f636f06.jpg"><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/c81e728d9d4c2f636f06.jpg" alt="2"></a></p><p>2.选择名称和客户机操作系统,按照图片选择就可以,选择完成后下一步</p><p><img src="https://www.bokezhu.com/content/uploads/2019/07/eccbc87e4b5ce2fe2830.jpg" alt="3"></p><p>3.选择存储,这里不要 操作直接下一步</p><p><a href="https://www.bokezhu.com/content/uploads/2019/07/a87ff679a2f3e71d9181.jpg"><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/a87ff679a2f3e71d9181.jpg" alt="4"></a></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/e4da3b7fbbce2345d777.jpg" alt="5"></p><p>5.自定义设置,这里需要删除硬盘1;SCSI控制器0;CD/DVD驱动器0,并且将网卡适配器类型改为E1000,不改可能将无法获取ip地址,修改完成下一步完成配置</p><p>6.下载黑群晖所需工具,下载地址:<a href="https://pan.baidu.com/s/1jCUjEyNht7KHd8UvujvJXA">https://pan.baidu.com/s/1jCUjEyNht7KHd8UvujvJXA</a> 提取码:nc3t 下载完成解压</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/6512bd43d9caa6e02c99.jpg" alt="11"></p><p>7.上传引导文件,在ESXI中找到刚才创建虚拟机位置上传synoboot和synoboot-flat到该文件夹</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/c20ad4d76fe97759aa27.jpg" alt="12"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/c51ce410c124a10e0db5.jpg" alt="13"></p><p>8.返回虚拟机找到刚才添加的虚拟机编辑设置,点击添加现有硬盘找到刚刚上传的synoboot选择保存</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/aab3238922bcc25a6f60.jpg" alt="14"></p><p>9.添加存储硬盘,注意:控制器位置应选择SATA控制器;SATA(0.1)再加一块硬盘应按照排序SATA(0.2),磁盘模式选择独立-持久后保存,启动虚拟机</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/9bf31c7ff062936a96d3.jpg" alt="15"></p><p>出现图上画面说明引导成功,进行下一步操作。</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/c74d97b01eae257e44aa.jpg" alt="16"></p><p>11.搜索黑群晖ip地址,登录路由器找到在线设备DiskStation就是该设备ip地址。也可以在工具包里找到synology-assistant来搜索ip地址</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/70efdf2ec9b086079795.jpg" alt="17"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/6f4922f45568161a8cdf.jpg" alt="18"></p><p>12.找到ip后在浏览器输入ip地址,点击设置到下一步;选择浏览找到工具包中DSM_DS3615xs_23824后点击立即安装,安装过程大概持续10分钟</p><p><img src="https://www.bokezhu.com/content/uploads/2019/07/98f13708210194c47568.jpg" alt="20"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/3c59dc048e8850243be8.jpg" alt="21"></p><p>13.安装完成后跳出创建您的管理员账户,输入服务器名称账号及密码下一步,将更新设置设置成手动安装,SMART检测和启动硬盘扇区警告勾选去掉下一步后不要输入账号直接跳过完成安装。</p><h3 id="硬盘直通之dsm直通-amp-sata直通"><a href="#硬盘直通之dsm直通-amp-sata直通" class="headerlink" title="硬盘直通之dsm直通&sata直通"></a>硬盘直通之dsm直通&sata直通</h3><blockquote><p>关于 RDM 和 Passthrough 的区别</p><p>如果你提前搜过资料可能会发现很多 ESXi 上安装黑群晖的教程中会提到以 “RDM 来把硬盘直通给群晖”,这实际上很扯淡的,因为 RDM 和设备直通是完全两个独立的概念。<br>一些有玩虚拟机经验的人简单看一下那些 RDM 硬盘直通教程就能发现问题,RDM 是将物理硬件虚拟化后再传递给虚拟机,也就是由 ESXi 读取设备后生成一个新的虚拟设备再传递给虚拟机。而硬件直通(Passthrough)是将物理主机上的设备直接规划给虚拟机独立使用,ESXi 系统不会再利用这个物理硬件。<br>这也就是为什么使用 RDM 虽然可以让群晖读到那么一整个硬盘,但硬盘名称总是 “VMWare 虚拟硬盘”,而使用 Passthrough 的硬盘永远都可以显示出正确的硬盘信息。在黑群晖中,使用 Passthrough 直通硬盘允许群晖系统对硬盘直接进行管理,包括但不限于硬盘休眠和硬盘健康度监测,这些功能使用 RDM 是不可能做到了,RDM 也仅仅做到了让虚拟机读到一个完整的硬盘。</p></blockquote><p>参考博客:<a href="https://blog.irain.in/archives/ESXi_Synology_10G_Passthrough.html">https://blog.irain.in/archives/ESXi_Synology_10G_Passthrough.html</a></p><p>我最终还是选择RDM 参考博客 <a href="https://www.cnblogs.com/vaemaxsky/p/13982648.html">https://www.cnblogs.com/vaemaxsky/p/13982648.html</a></p><h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>群晖的硬盘设置很重要,不然很容易出现各种奇奇怪怪的问题,我遇到过不进系统,引导后到安装步骤时识别不了硬盘</p><h2 id="iKuai安装"><a href="#iKuai安装" class="headerlink" title="iKuai安装"></a>iKuai安装</h2><p>很简单 不赘述</p><h2 id="LEDE安装"><a href="#LEDE安装" class="headerlink" title="LEDE安装"></a>LEDE安装</h2><p> 科学备份 <a href="https://github.com/izyq/fancyss_history_package">https://github.com/izyq/fancyss_history_package</a> </p><p>参考博客 <a href="https://post.smzdm.com/p/awxq6zvm/">https://post.smzdm.com/p/awxq6zvm/</a> </p><p><a href="https://www.cnblogs.com/vaemaxsky/p/13982648.html">https://www.cnblogs.com/vaemaxsky/p/13982648.html</a></p><p><a href="https://firmware.koolshare.cn/LEDE_X64_fw867/%E8%99%9A%E6%8B%9F%E6%9C%BA%E8%BD%AC%E7%9B%98%E6%88%96PE%E4%B8%8B%E5%86%99%E7%9B%98%E4%B8%93%E7%94%A8/">https://firmware.koolshare.cn/LEDE_X64_fw867/%E8%99%9A%E6%8B%9F%E6%9C%BA%E8%BD%AC%E7%9B%98%E6%88%96PE%E4%B8%8B%E5%86%99%E7%9B%98%E4%B8%93%E7%94%A8/</a></p><p> </p><p> </p>]]></content>
<categories>
<category> 折腾 </category>
</categories>
<tags>
<tag> 折腾 </tag>
<tag> ESXI </tag>
</tags>
</entry>
<entry>
<title>老毛子内网ddns</title>
<link href="2021/04/24/lao-mao-zi-nei-wang-ddns/"/>
<url>2021/04/24/lao-mao-zi-nei-wang-ddns/</url>
<content type="html"><![CDATA[<p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/20210424233043.png"></p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">ifconfig</span> <span class="token variable"><span class="token variable">$(</span>nvram get wan0_ifname_t<span class="token variable">)</span></span> <span class="token operator">|</span> <span class="token function">awk</span> -F <span class="token string">":"</span> <span class="token string">'{print <span class="token variable">$2</span>}'</span> <span class="token operator">|</span> <span class="token function">grep</span> -E -o <span class="token string">'([0-9]+\.){3}[0-9]+'</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>主要是<code>ifconfig $(nvram get wan0_ifname_t)</code>获取本地ip信息,再通过<code>awk</code>和<code>grep</code>提取</p>]]></content>
</entry>
<entry>
<title>STM32初探</title>
<link href="2021/03/26/stm32-chu-tan/"/>
<url>2021/03/26/stm32-chu-tan/</url>
<content type="html"><![CDATA[<h4 id="设置堆栈-初始化环境"><a href="#设置堆栈-初始化环境" class="headerlink" title="设置堆栈 初始化环境"></a>设置堆栈 初始化环境</h4><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326002304906.png"></p><h4 id="添加头文件"><a href="#添加头文件" class="headerlink" title="添加头文件"></a>添加头文件</h4><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326003410932.png"></p><h4 id="选择正确的型号-点开魔法棒"><a href="#选择正确的型号-点开魔法棒" class="headerlink" title="选择正确的型号(点开魔法棒)"></a>选择正确的型号(点开魔法棒)</h4><h4 id=""><a href="#" class="headerlink" title=""></a><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326003646779.png"></h4><h4 id="时钟"><a href="#时钟" class="headerlink" title="时钟"></a>时钟</h4><p>控制外设使能与否就是控制这个外设的时钟</p><p>以LED为例</p><ul><li>查看原理图</li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326203623033.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326203806652.png"></p><ul><li>查看总线架构</li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326204617751.png"></p><ul><li>找到RCC(复位和时钟控制) 基地址<ul><li>基地址:0x4002 3800 </li></ul></li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326205508116.png"></p><ul><li>接着找到RCC AHB1 外设时钟使能寄存器 (RCC_AHB1ENR)<ul><li>得到 偏移地址:0x30</li></ul></li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326210058931.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326213943927.png"></p><p><strong>RCC_AHB1ENR的地址就为基地址 + 偏移地址</strong> 其他以此类推</p><ul><li>AHB1 外设时钟使能寄存器 使能</li></ul><h4 id="推挽模式-寄存器操作-控制时钟"><a href="#推挽模式-寄存器操作-控制时钟" class="headerlink" title="推挽模式 寄存器操作 控制时钟"></a>推挽模式 寄存器操作 控制时钟</h4><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326011033237.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326011158591.png"></p><p>配置寄存器进行相应的模式配置 </p><h4 id="通过端口配置表(表28)配置相应的位配置不同的模式"><a href="#通过端口配置表(表28)配置相应的位配置不同的模式" class="headerlink" title="通过端口配置表(表28)配置相应的位配置不同的模式"></a>通过端口配置表(表28)配置相应的位配置不同的模式</h4><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326211412621.png"></p><p>再次展示我们的原理图</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326203623033.png"></p><p>注:<details></p><summary><mark><font color=darkred>点击查看详细配置内容</font></mark></summary><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326212258547.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326212318462.png"></p><p><strong>OT0 OT1 分别对应GPIO端口0 端口1 以此类推</strong></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326011500510.png"></p><p>(输出速度越快 功耗越大 这里的速度指的是GPIO电平翻转的速度 就是高低电平变化的速度)</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326212439536.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326212455084.png"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/Pic@master/image-20210326220500358.png"></p></details><pre class="line-numbers language-c" data-language="c"><code class="language-c"><span class="token comment">/*使用寄存器的方法点亮LED灯 */</span><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">"stm32f4xx.h"</span> </span><span class="token comment">/** * 主函数 */</span><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token comment">/*开启 GPIOH 时钟,使用外设时都要先开启它的时钟*/</span>RCC_AHB1ENR <span class="token operator">|=</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token operator"><<</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/* LED 端口初始化 */</span><span class="token comment">/*GPIOH MODER10清空*/</span>GPIOH_MODER <span class="token operator">&=</span> <span class="token operator">~</span><span class="token punctuation">(</span> <span class="token number">0x03</span><span class="token operator"><<</span> <span class="token punctuation">(</span><span class="token number">2</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*PH10 MODER10 = 01b 输出模式*/</span>GPIOH_MODER <span class="token operator">|=</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token operator"><<</span><span class="token number">2</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*GPIOH OTYPER10清空*/</span>GPIOH_OTYPER <span class="token operator">&=</span> <span class="token operator">~</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator"><<</span><span class="token number">1</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*PH10 OTYPER10 = 0b 推挽模式*/</span>GPIOH_OTYPER <span class="token operator">|=</span> <span class="token punctuation">(</span><span class="token number">0</span><span class="token operator"><<</span><span class="token number">1</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*GPIOH OSPEEDR10清空*/</span>GPIOH_OSPEEDR <span class="token operator">&=</span> <span class="token operator">~</span><span class="token punctuation">(</span><span class="token number">0x03</span><span class="token operator"><<</span><span class="token number">2</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*PH10 OSPEEDR10 = 0b 速率2MHz*/</span>GPIOH_OSPEEDR <span class="token operator">|=</span> <span class="token punctuation">(</span><span class="token number">0</span><span class="token operator"><<</span><span class="token number">2</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*GPIOH PUPDR10清空*/</span>GPIOH_PUPDR <span class="token operator">&=</span> <span class="token operator">~</span><span class="token punctuation">(</span><span class="token number">0x03</span><span class="token operator"><<</span><span class="token number">2</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*PH10 PUPDR10 = 01b 上拉模式*/</span>GPIOH_PUPDR <span class="token operator">|=</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token operator"><<</span><span class="token number">2</span><span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*PH10 BSRR寄存器的 BR10置1,使引脚输出低电平*/</span>GPIOH_BSRR <span class="token operator">|=</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token operator"><<</span><span class="token number">16</span><span class="token operator"><<</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*PH10 BSRR寄存器的 BS10置1,使引脚输出高电平*/</span><span class="token comment">//GPIOH_BSRR |= (1<<10);</span><span class="token keyword">while</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token comment">// 函数为空,目的是为了骗过编译器不报错</span><span class="token keyword">void</span> <span class="token function">SystemInit</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<categories>
<category> 嵌入式 </category>
</categories>
<tags>
<tag> STM32 </tag>
</tags>
</entry>
<entry>
<title>C语言</title>
<link href="2021/03/21/c-yu-yan/"/>
<url>2021/03/21/c-yu-yan/</url>
<content type="html"><![CDATA[<h3 id="温故而知新"><a href="#温故而知新" class="headerlink" title="温故而知新"></a>温故而知新</h3><h4 id="位操作"><a href="#位操作" class="headerlink" title="位操作"></a>位操作</h4><p>(1<<3)<br>取反 ~0xf<<(4*0) 什么意思<br>与 或 操作</p><h4 id="按位取反"><a href="#按位取反" class="headerlink" title="按位取反~"></a>按位取反<code>~</code></h4><p>逻辑位运算符中优先级最高,运算符<code>~</code>符号,作用是将1变成0,将0变成1</p><pre class="line-numbers language-none"><code class="language-none">~ 1010 1111 0101 0000<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><h4 id="按位与-amp"><a href="#按位与-amp" class="headerlink" title="按位与&"></a>按位与<code>&</code></h4><p>优先级第二高,运算符<code>&</code>,存在一个位为0,则结果为0,两个位为1,结果才为1</p><pre class="line-numbers language-none"><code class="language-none">1010 1111&1010 01011010 0101<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h4 id="按位异或"><a href="#按位异或" class="headerlink" title="按位异或^"></a>按位异或<code>^</code></h4><p>优先级第三,运算符<code>^</code>,两个操作数相同时,结果为0,不同时,结果为1。</p><pre class="line-numbers language-none"><code class="language-none">1111 1111^1111 11110000 00001111 1111^0000 00001111 11111010 1111^1010 01010000 1010<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h4 id="按位或"><a href="#按位或" class="headerlink" title="按位或|"></a>按位或<code>|</code></h4><p>优先级最后 运算符<code>|</code> ,存在一个位为1,则结果为1,两个位为0,结果才为0</p>]]></content>
<categories>
<category> C语言 </category>
</categories>
<tags>
<tag> C语言 </tag>
</tags>
</entry>
<entry>
<title>Matery的修改与美化</title>
<link href="2021/01/23/matery/"/>
<url>2021/01/23/matery/</url>
<content type="html"><![CDATA[<h2 id="修改过的文件"><a href="#修改过的文件" class="headerlink" title="修改过的文件"></a>修改过的文件</h2><p><code>hexo-theme-matery\_config.yml</code><br><code>hexo-theme-matery\source\css\matery.css</code><br><code>hexo-theme-matery\layout\_partial\bg-cover-content.ejs</code><br><code>hexo-theme-matery\layout\_partial\post-cover.ejs</code><br><code>hexo-theme-matery\layout\_partial\post-detail.ejs</code><br><code>hexo-theme-matery\layout\_partial\post-detail-toc.ejs</code><br><code>hexo-theme-matery\layout\_partial\github-link.ejs</code><br><code>hexo-theme-matery\layout\_partial\footer.ejs</code><br><code>hexo-theme-matery\layout\about.ejs</code></p><p>可以从<a href="https://github.com/izyq/Matery-officialcodebackup" title="我当初用的源码">我当初用的源码</a>进行比较知道修改了哪些地方</p><h2 id="安装的依赖"><a href="#安装的依赖" class="headerlink" title="安装的依赖"></a>安装的依赖</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">cnpm <span class="token function">install</span> hexo-admin --savecnpm i --save hexo-wordcountcnpm i hexo-permalink-pinyin --savecnpm <span class="token function">install</span> hexo-generator-search --savecnpm <span class="token function">install</span> hexo-deployer-git --save<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<categories>
<category> 折腾 </category>
</categories>
<tags>
<tag> Hexo </tag>
<tag> Matery </tag>
</tags>
</entry>
<entry>
<title>杂记</title>
<link href="2020/10/15/za-ji/"/>
<url>2020/10/15/za-ji/</url>
<content type="html"><![CDATA[<h2 id="群晖-为dsvideo目录添加自动索引"><a href="#群晖-为dsvideo目录添加自动索引" class="headerlink" title="群晖- 为dsvideo目录添加自动索引"></a>群晖- 为dsvideo目录添加自动索引</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">synoindex -R /volume2/video/Download<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h2 id="linux-下后台运行python脚本"><a href="#linux-下后台运行python脚本" class="headerlink" title="linux 下后台运行python脚本"></a>linux 下后台运行python脚本</h2><h3 id="一、启动命令:"><a href="#一、启动命令:" class="headerlink" title="一、启动命令:"></a>一、启动命令:</h3><p>1、一般使用</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">nohup</span> python -u Job.py <span class="token operator">></span> log.log <span class="token operator"><span class="token file-descriptor important">2</span>></span><span class="token file-descriptor important">&1</span> <span class="token operator">&</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>2、只记录异常日志(推荐)</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># nohup python -u Job.py >/dev/null 2>error.log 2>&1 &</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>3、不记录任何日志</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># nohup python -u Job.py >/dev/null 2>&1 & </span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h4 id="说明:"><a href="#说明:" class="headerlink" title="说明:"></a>说明:</h4><ol><li>末尾的“&”:表示后台运行程序</li><li>“nohup” :保证程序不被挂起</li><li>“python”:是执行python代码的命令</li><li>“-u”:表示不启用缓存,实时输出打印信息到日志文件(如果不加-u,则会导致日志文件不会实时刷新代码中的print函数的信息)</li><li>“Job.py”:是python的源代码文件</li><li>“log.log”:是输出的日志文件</li><li>“>”:是指将打印信息指定到日志文件</li><li>“2>&1”:将标准错误输出转变化标准输出,可以将错误信息也输出到日志文件中(0-> stdin, 1->stdout, 2->stderr)</li></ol><h3 id="二、关闭命令"><a href="#二、关闭命令" class="headerlink" title="二、关闭命令"></a>二、关闭命令</h3><p>1、查看进程</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># ps -ef|grep python</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>或者</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># ps -ef|grep Job</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>2、关闭进程</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># kill -9 19913</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>3、检查</p><p>用1中查看进程的命令,检查或确认进程是否真正被关闭。</p>]]></content>
<categories>
<category> Others </category>
</categories>
<tags>
<tag> Linux </tag>
<tag> Python </tag>
<tag> 群晖 </tag>
</tags>
</entry>
<entry>
<title>Linux系统inodes资源耗尽问题 </title>
<link href="2020/09/19/inodes/"/>
<url>2020/09/19/inodes/</url>
<content type="html"><![CDATA[<h1 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h1><p> 今天服务器突然崩了,使用的amh面板,执行<code>/etc/init.d/amh-start</code>后所有服务均出现相同的一个错误提示<code>No space left on device</code></p><h1 id="解决"><a href="#解决" class="headerlink" title="解决"></a>解决</h1><h3 id="排查"><a href="#排查" class="headerlink" title="排查"></a>排查</h3><p>查看磁盘空间使用情况,使用<code>df -h</code>命令,磁盘显然没有占满,那是什么问题呢?一番搜寻后发现居然有个叫inode的东西。引起了我的注意。</p><h3 id="查看inodess使用情况,使用df-i命令"><a href="#查看inodess使用情况,使用df-i命令" class="headerlink" title="查看inodess使用情况,使用df -i命令"></a>查看inodess使用情况,使用<code>df -i</code>命令</h3><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/inode/pasted-0.png" alt="奔跑博客"><br>由于我没有截图,所以借用一张网图。</p><h3 id="inodes耗尽解决"><a href="#inodes耗尽解决" class="headerlink" title="inodes耗尽解决"></a>inodes耗尽解决</h3><ul><li>(1)查看文件最多的目录</li></ul><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token keyword">for</span> <span class="token for-or-select variable">i</span> <span class="token keyword">in</span> /*<span class="token punctuation">;</span> <span class="token keyword">do</span> <span class="token builtin class-name">echo</span> <span class="token variable">$i</span><span class="token punctuation">;</span> <span class="token function">find</span> <span class="token variable">$i</span> <span class="token operator">|</span> <span class="token function">wc</span> -l<span class="token punctuation">;</span> <span class="token keyword">done</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p> 如果确定目录范围,把/*写的具体点</p><p>最终发现是<code>/var/spool/postfix/maildrop</code>目录下小文件过多,原因如下:</p><p><em>由于linux在执行cron时,会将cron执行脚本中的output和warning信息,都会以邮件的形式发送给cron所有者。由于客户环境中的sendmail和postfix没有正常运行,邮件发送不成功,导致全部小文件都堆积在maildrop目录下,另由于缺乏自动清理的机制,故此目录下堆积了大量的文件。</em></p><ul><li>(2)删除大量文件</li></ul><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">ls</span> <span class="token operator">|</span> <span class="token function">xargs</span> -n <span class="token number">1000</span> <span class="token function">rm</span> -rf<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>需要使用<code>xargs</code>命令,不然会删除失败。</p><h1 id="inodes介绍"><a href="#inodes介绍" class="headerlink" title="inodes介绍"></a>inodes介绍</h1><p>Linux系统下文件数据储存在”块”中,文件的元信息,例如文件的创建者、文件的创建日期、文件的大小等。这种储存文件元信息的区域就叫做inode,中文译名为”索引节点”。</p><p>inode也占用硬盘空间,硬盘格式化的时候,操作系统自动将硬盘分成两个区域。一个是数据区,存放文件数据;另一个是inode区(inode table),存放inode所包含的信息。</p><p>每个inode节点的大小,一般是128字节或256字节。inode节点的总数,在格式化时就给定,一般是每1KB或每2KB就设置一个inode。假定在一块1GB的硬盘中,每个inode节点的大小为128字节,每1KB就设置一个inode,那么inode table的大小就会达到128MB,占整块硬盘的12.8%。</p>]]></content>
<categories>
<category> 折腾 </category>
</categories>
<tags>
<tag> Linux </tag>
</tags>
</entry>
<entry>
<title>Open薇屁嗯实现静态ip </title>
<link href="2020/08/24/openvpn/"/>
<url>2020/08/24/openvpn/</url>
<content type="html"><![CDATA[<blockquote><ul><li>由于我的电脑p775太重,学校某些地方端口封锁,而我又需要一个稳定的远程连接方式,于是开始折腾起自己家里的网件R6400。</li></ul></blockquote><h1 id="前期准备"><a href="#前期准备" class="headerlink" title="前期准备"></a>前期准备</h1><p><strong>对于要向其分配静态IP地址的每个OpenVPN客户端,您需要从该特定客户端证书中提取通用名称。</strong></p><p>我的路由器使用的是梅林固件,<code>Firmware:380.70_0-X7.9</code>,我在vpn配置好用户名和密码后发现每个连接的<em>common name</em>都是client,没法给每个用户名单独配置,我苦苦寻求方法无果后,偶然发现在高级设置里面开启这两项,用户名就成了common name</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/openvp/pasted-1.png" alt="奔跑博客"></p><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/openvp/pasted-2.png" alt="奔跑博客"></p><h1 id="为Open薇屁嗯客户端分配静态IP地址"><a href="#为Open薇屁嗯客户端分配静态IP地址" class="headerlink" title="为Open薇屁嗯客户端分配静态IP地址"></a>为Open薇屁嗯客户端分配静态IP地址</h1><h2 id="创建一个文件来存储静态IP地址"><a href="#创建一个文件来存储静态IP地址" class="headerlink" title="创建一个文件来存储静态IP地址"></a>创建一个文件来存储静态IP地址</h2><p>有了<code>common name</code>后,一切都变得好办起来。<br>使用 client-config-dir 选项,要求将分配给连接客户端的静态IP地址存储在OpenVPN服务器可以读取的文件中。<br>在R6400中,我们在高级设置 自定义配置中添加一行</p><pre class="line-numbers language-none"><code class="language-none">client-config-dir /etc/ccd #路径可以更改<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/openvp/pasted-3.png" alt="奔跑博客"></p><h2 id="为OpenVPN客户端分配静态IP地址"><a href="#为OpenVPN客户端分配静态IP地址" class="headerlink" title="为OpenVPN客户端分配静态IP地址"></a>为OpenVPN客户端分配静态IP地址</h2><p>有了客户端的通用名称后,您就可以使用 ifconfig-push 选项。<br>例如,给通用名称为<strong>ipad</strong>的客户端分配静态ip地址:</p><pre class="line-numbers language-none"><code class="language-none">mkdir /etc/ccdecho ifconfig-push 10.8.0.10 255.255.255.0 > /etc/ccd/gx8<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p>然后输入用户名gx8和密码重新连接,open薇屁嗯就会分配你设定好的ip地址</p><h2 id="不完美与瑕疵"><a href="#不完美与瑕疵" class="headerlink" title="不完美与瑕疵"></a>不完美与瑕疵</h2><p>R6400ssh连接用admin用户登陆没有root权限,而etc根目录的etc文件是tmp文件夹里的一个软链接,这意味着路由器每次重启你都需要重新创建这样一个文件,后面再去研究怎么解决这个问题吧!</p><h1 id="补充-win10-open薇屁嗯-UI-的开机自动连接设置方法"><a href="#补充-win10-open薇屁嗯-UI-的开机自动连接设置方法" class="headerlink" title="补充 win10 open薇屁嗯 UI 的开机自动连接设置方法"></a>补充 win10 open薇屁嗯 UI 的开机自动连接设置方法</h1><p>如图所示,给openvpn的快捷方式目标里面加上这一句</p><pre class="line-numbers language-none"><code class="language-none">--connect client1.ovpn #clint1是你的配置文件名称,根据实际情况自行修改<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/openvp/pasted-4.png" alt="奔跑博客"><br>然后按win+R ,输入<code>shell:startup</code>,把改好的快捷方式复制进去便大功告成啦</p>]]></content>
<categories>
<category> 折腾 </category>
</categories>
<tags>
<tag> VPN </tag>
</tags>
</entry>
<entry>
<title>python实现强智科技教务系统抢课(两种方法) </title>
<link href="2020/08/01/qiang-ke/"/>
<url>2020/08/01/qiang-ke/</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>又到了选课的时间,又一次被教务系统的预选给安排了,硬是一门都没选中。于是想实现有没有自动捡课的方法。就整体分为两种方法,一种是获取get请求然后由python多线程提交去选课,一种是利用自动化测试的selenium库去调用谷歌浏览器模拟人工选课操作。其实就算都是强智系统,但细节上还是有些差别的。所以也有可能无法实现。这里放出两种方法的代码和流程,仅供参考。</p><h2 id="方法一:"><a href="#方法一:" class="headerlink" title="方法一:"></a>方法一:</h2><p>直接提交选课的数据包(需要cookie和课程ID),先用同学的账号登录教务系统,进入到选课的地方,打开浏览器的开发模式(按F12),点击Network()我这里是谷歌浏览器,如果是其他的找到网络抓包即可。</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/qiang-k/pasted-0.png" alt="奔跑博客"></p><p>点击你想选择课程的选课按钮,得到我们需要的数据包。</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/qiang-k/pasted-1.png" alt="奔跑博客"></p><p>我们来看下这个数据包的内容,我们需要找到cookie( 你的身份标识),以及我们需要选的课程ID,然后用python模拟提交就OK了。</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/qiang-k/pasted-2.png" alt="奔跑博客"></p><p>注意 代码里的User_Agent和Referer也要记得修改,都在数据包里。</p><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/qiang-k/pasted-3.png" alt="奔跑博客"></p><p>下面是代码:</p><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> requests<span class="token keyword">from</span> future<span class="token punctuation">.</span>backports<span class="token punctuation">.</span>test<span class="token punctuation">.</span>ssl_servers <span class="token keyword">import</span> threading <span class="token comment"># 获取cookie 和 课程id就可以抢课</span> <span class="token keyword">def</span> <span class="token function">qian1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> data <span class="token operator">=</span> <span class="token number">201820192001656</span> <span class="token comment"># data 是找到的课程ID,因为python没学好,代码写的有点乱</span> <span class="token comment"># 下面是地址 就是我们抓到的那个数据包的URL</span> url <span class="token operator">=</span> <span class="token string">'http://****(学校的地址).edu.cn/jsxsd/xsxkkc/bxxkOper?jx0404id='</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span> cookie <span class="token operator">=</span> <span class="token string">' 用找到的cookie替换'</span> header <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">'User-Agent'</span><span class="token punctuation">:</span> <span class="token string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'</span><span class="token punctuation">,</span> <span class="token string">'Referer'</span><span class="token punctuation">:</span> <span class="token string">'http://........../srun_portal_pc.php?ac_id=1'</span><span class="token punctuation">,</span> <span class="token string">'cookie'</span><span class="token punctuation">:</span>cookie <span class="token punctuation">}</span> <span class="token comment"># 一直抢!</span> <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span> <span class="token comment"># 设定5s服务器未应答就放弃这次,鬼知道是服务器炸了还是。。。。</span> mes <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">,</span> headers<span class="token operator">=</span>header<span class="token punctuation">,</span> timeout<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token comment"># 打印返回的结果,就是弹出来的那个小窗口的内容</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>mes<span class="token punctuation">.</span>status_code<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">':'</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>mes<span class="token punctuation">.</span>text<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment"># 后面是不同的课,因为不能吊在一课树上!</span><span class="token keyword">def</span> <span class="token function">qian</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> data <span class="token operator">=</span> <span class="token number">201820192001302</span> url <span class="token operator">=</span> <span class="token string">'http://*****/jsxsd/xsxkkc/bxxkOper?jx0404id='</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span> cookie <span class="token operator">=</span> <span class="token string">'*****cookie'</span> header <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">'User-Agent'</span><span class="token punctuation">:</span> <span class="token string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'</span><span class="token punctuation">,</span> <span class="token string">'Referer'</span><span class="token punctuation">:</span> <span class="token string">'http://172.30.1.70/srun_portal_pc.php?ac_id=1'</span><span class="token punctuation">,</span> <span class="token string">'cookie'</span><span class="token punctuation">:</span>cookie <span class="token punctuation">}</span> <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span> mes <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">,</span> headers<span class="token operator">=</span>header<span class="token punctuation">,</span> timeout<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>mes<span class="token punctuation">.</span>status_code<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">':'</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>mes<span class="token punctuation">.</span>text<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">def</span> <span class="token function">qian2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> data <span class="token operator">=</span> <span class="token number">201820192001155</span> url <span class="token operator">=</span> <span class="token string">'http://****n/jsxsd/xsxkkc/bxxkOper?jx0404id='</span> <span class="token operator">+</span> <span class="token builtin">str</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span> cookie <span class="token operator">=</span> <span class="token string">'cookie'</span> header <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">'User-Agent'</span><span class="token punctuation">:</span> <span class="token string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'</span><span class="token punctuation">,</span> <span class="token string">'Referer'</span><span class="token punctuation">:</span> <span class="token string">'http://172.30.1.70/srun_portal_pc.php?ac_id=1'</span><span class="token punctuation">,</span> <span class="token string">'cookie'</span><span class="token punctuation">:</span> cookie <span class="token punctuation">}</span> <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span> mes <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">,</span> headers<span class="token operator">=</span>header<span class="token punctuation">,</span> timeout<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>mes<span class="token punctuation">.</span>status_code<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">':'</span> <span class="token operator">+</span> <span class="token builtin">str</span><span class="token punctuation">(</span>mes<span class="token punctuation">.</span>text<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment"># 开多线程分开抢课</span> <span class="token comment"># 接下来就会一直抢课!</span> thread1 <span class="token operator">=</span> threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>qian<span class="token punctuation">)</span> thread2 <span class="token operator">=</span> threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>qian1<span class="token punctuation">)</span> thread3 <span class="token operator">=</span> threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>qian2<span class="token punctuation">)</span> thread4 <span class="token operator">=</span> threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>qian<span class="token punctuation">)</span> thread5 <span class="token operator">=</span> threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>qian1<span class="token punctuation">)</span> thread6 <span class="token operator">=</span> threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>qian2<span class="token punctuation">)</span> thread1<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span> thread2<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span> thread3<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span> thread4<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span> thread5<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span> thread6<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span> main<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="方法二:selenium库模拟人工选课"><a href="#方法二:selenium库模拟人工选课" class="headerlink" title="方法二:selenium库模拟人工选课"></a>方法二:selenium库模拟人工选课</h2><p>要使用这个方法之前,最好先看一下这一篇文章,<a href="https://blog.csdn.net/weixin_43314519/article/details/107092245">了解如何使用selenium库</a>。记得提前安装好selenium库,以及Chromedriver。具体方法可以在csdn搜索。</p><h3 id="使用流程"><a href="#使用流程" class="headerlink" title="使用流程"></a>使用流程</h3><ol><li>将脚本内信息填好改好</li><li>运行脚本,此时会打开chrome并且打开登录页,脚本会自行填写学号密码,需要等你填写验证码</li></ol><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment"># author: Zmaster</span><span class="token comment"># time: 2020/7/2 12:03</span><span class="token comment"># -*- coding: utf-8 -*-</span><span class="token keyword">from</span> selenium <span class="token keyword">import</span> webdriver<span class="token keyword">from</span> selenium<span class="token punctuation">.</span>webdriver<span class="token punctuation">.</span>common<span class="token punctuation">.</span>keys <span class="token keyword">import</span> Keys<span class="token keyword">from</span> time <span class="token keyword">import</span> sleepchrome_options <span class="token operator">=</span> webdriver<span class="token punctuation">.</span>ChromeOptions<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token keyword">class</span> <span class="token class-name">Qiangke</span><span class="token punctuation">(</span><span class="token builtin">object</span><span class="token punctuation">)</span><span class="token punctuation">:</span> login_url <span class="token operator">=</span> <span class="token string">"https://***.edu.cn/jsxsd/"</span> <span class="token comment">#登录页面,修改成你学校的登录地址</span> select_url <span class="token operator">=</span> <span class="token string">"****/jsxsd/xsxk/xsxk_index?jx0502zbid=B563D5935D024C6387445066336AA73B"</span><span class="token comment">#修改为登录成功后的界面</span> initmy_url <span class="token operator">=</span> <span class="token string">"https://****/jsxsd/framework/xsMain.jsp"</span> <span class="token comment">#修改为你选课的界面</span> xh <span class="token operator">=</span> <span class="token string">u"****"</span> <span class="token comment">#填写用户名</span> pwd <span class="token operator">=</span> <span class="token string">'****'</span> <span class="token comment">#填写密码</span> _user <span class="token operator">=</span> <span class="token string">"****@qq.com"</span> <span class="token comment">#填写你的邮箱(用于发邮件提醒抢课成功)</span> _pwd <span class="token operator">=</span> <span class="token string">"****"</span> <span class="token comment">#授权码,在邮箱里获得</span> _to <span class="token operator">=</span> <span class="token string">"****@qq.com"</span> <span class="token comment">#收件人邮箱,可以写自己的,帮别人抢课就发别人的</span> course_category <span class="token operator">=</span> <span class="token string">u'公选课选课'</span> <span class="token comment"># 这里填写选课种类,这个脚本只能抢跨年级,跨专业,和公选,需输入完整的名字如“专业内跨年级选课”,“跨专业选课”,“公选课选课”</span> class_name <span class="token operator">=</span> <span class="token string">u"美术赏析"</span> <span class="token comment">#这里输入你想抢的课的名字(关键字即可)</span> teacher_name <span class="token operator">=</span> <span class="token string">u""</span> <span class="token comment">#这里输入你想抢的课的老师的名字</span> <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"开始抢课"</span><span class="token punctuation">)</span> <span class="token keyword">def</span> <span class="token function">login</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>get<span class="token punctuation">(</span>self<span class="token punctuation">.</span>login_url<span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_id<span class="token punctuation">(</span><span class="token string">"details-button"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>click<span class="token punctuation">(</span><span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_id<span class="token punctuation">(</span><span class="token string">"proceed-link"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>click<span class="token punctuation">(</span><span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_name<span class="token punctuation">(</span><span class="token string">"USERNAME"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>send_keys<span class="token punctuation">(</span>self<span class="token punctuation">.</span>xh<span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_name<span class="token punctuation">(</span><span class="token string">"PASSWORD"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>send_keys<span class="token punctuation">(</span>self<span class="token punctuation">.</span>pwd<span class="token punctuation">)</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"等待验证码,自行输入...."</span><span class="token punctuation">)</span> <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span> <span class="token keyword">if</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>current_url <span class="token operator">!=</span> self<span class="token punctuation">.</span>initmy_url<span class="token punctuation">:</span> sleep<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">else</span><span class="token punctuation">:</span> <span class="token keyword">break</span> <span class="token keyword">def</span> <span class="token function">send</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> text<span class="token punctuation">,</span> send_msg<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">import</span> smtplib <span class="token keyword">from</span> email<span class="token punctuation">.</span>mime<span class="token punctuation">.</span>text <span class="token keyword">import</span> MIMEText msg <span class="token operator">=</span> MIMEText<span class="token punctuation">(</span>text<span class="token punctuation">)</span> msg<span class="token punctuation">[</span><span class="token string">"Subject"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"你选课成功了!"</span> msg<span class="token punctuation">[</span><span class="token string">"From"</span><span class="token punctuation">]</span> <span class="token operator">=</span> self<span class="token punctuation">.</span>_user msg<span class="token punctuation">[</span><span class="token string">"To"</span><span class="token punctuation">]</span> <span class="token operator">=</span> self<span class="token punctuation">.</span>_to s <span class="token operator">=</span> smtplib<span class="token punctuation">.</span>SMTP_SSL<span class="token punctuation">(</span><span class="token string">"smtp.qq.com"</span><span class="token punctuation">,</span> <span class="token number">465</span><span class="token punctuation">)</span> s<span class="token punctuation">.</span>login<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_user<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_pwd<span class="token punctuation">)</span> s<span class="token punctuation">.</span>sendmail<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_user<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_to<span class="token punctuation">,</span> msg<span class="token punctuation">.</span>as_string<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> s<span class="token punctuation">.</span>quit<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">def</span> <span class="token function">start</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment"># 这里需要根据自己的教务系统去修改了,有挺多不一样的地方。所以建议阅读完使用文档再来修改</span> self<span class="token punctuation">.</span>driver <span class="token operator">=</span> webdriver<span class="token punctuation">.</span>Chrome<span class="token punctuation">(</span>chrome_options<span class="token operator">=</span>chrome_options<span class="token punctuation">)</span> self<span class="token punctuation">.</span>login<span class="token punctuation">(</span><span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>get<span class="token punctuation">(</span>self<span class="token punctuation">.</span>select_url<span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_link_text<span class="token punctuation">(</span>self<span class="token punctuation">.</span>course_category<span class="token punctuation">)</span><span class="token punctuation">.</span>click<span class="token punctuation">(</span><span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>switch_to<span class="token punctuation">.</span>frame<span class="token punctuation">(</span>self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_xpath<span class="token punctuation">(</span><span class="token string">'//*[@id="mainFrame"]'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_id<span class="token punctuation">(</span><span class="token string">'kcxx'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>send_keys<span class="token punctuation">(</span>self<span class="token punctuation">.</span>class_name<span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_id<span class="token punctuation">(</span><span class="token string">'skls'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>send_keys<span class="token punctuation">(</span>self<span class="token punctuation">.</span>teacher_name<span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_value<span class="token punctuation">(</span><span class="token string">u"查询"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>click<span class="token punctuation">(</span><span class="token punctuation">)</span> cnt <span class="token operator">=</span> <span class="token number">1</span> <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span> <span class="token keyword">try</span><span class="token punctuation">:</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_link_text<span class="token punctuation">(</span><span class="token string">'选课'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>click<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">except</span><span class="token punctuation">:</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>switch_to<span class="token punctuation">.</span>default_content<span class="token punctuation">(</span><span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>switch_to<span class="token punctuation">.</span>frame<span class="token punctuation">(</span>self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_xpath<span class="token punctuation">(</span><span class="token string">'//*[@id="mainFrame"]'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>find_element_by_link_text<span class="token punctuation">(</span><span class="token string">"选课"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>click<span class="token punctuation">(</span><span class="token punctuation">)</span> dig_alert <span class="token operator">=</span> self<span class="token punctuation">.</span>driver<span class="token punctuation">.</span>switch_to<span class="token punctuation">.</span>alert dig_alert<span class="token punctuation">.</span>accept<span class="token punctuation">(</span><span class="token punctuation">)</span> text <span class="token operator">=</span> dig_alert<span class="token punctuation">.</span>text <span class="token keyword">if</span> text <span class="token operator">!=</span> <span class="token string">'选课失败:此课堂选课人数已满!'</span> <span class="token keyword">and</span> text <span class="token operator">!=</span> <span class="token string">''</span><span class="token punctuation">:</span> self<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string">'{} 选课成功'</span><span class="token punctuation">.</span><span class="token builtin">format</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>class_name<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">break</span> <span class="token keyword">elif</span> text <span class="token operator">==</span> <span class="token string">''</span><span class="token punctuation">:</span> dig_alert<span class="token punctuation">.</span>accept<span class="token punctuation">(</span><span class="token punctuation">)</span> cnt <span class="token operator">+=</span> <span class="token number">1</span> <span class="token keyword">if</span> cnt <span class="token operator">%</span> <span class="token number">200</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">:</span> <span class="token keyword">print</span><span class="token punctuation">(</span>cnt<span class="token punctuation">)</span><span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">"__main__"</span><span class="token punctuation">:</span> qiangke <span class="token operator">=</span> Qiangke<span class="token punctuation">(</span><span class="token punctuation">)</span> qiangke<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<categories>
<category> 折腾 </category>
</categories>
<tags>
<tag> Python </tag>
</tags>
</entry>
<entry>
<title>正则表达式30min入门 </title>
<link href="2020/07/31/zheng-ze/"/>
<url>2020/07/31/zheng-ze/</url>
<content type="html"><![CDATA[<h3 id="看到一个很不错的文章,转载一下,以后需要就翻翻,顺便给自己标一下重点"><a href="#看到一个很不错的文章,转载一下,以后需要就翻翻,顺便给自己标一下重点" class="headerlink" title="看到一个很不错的文章,转载一下,以后需要就翻翻,顺便给自己标一下重点"></a>看到一个很不错的文章,转载一下,以后需要就翻翻,顺便给自己标一下重点</h3><p><code>原文链接:https://deerchao.cn/tutorials/regex/regex.htm </code></p><h3 id="如何使用本教程"><a href="#如何使用本教程" class="headerlink" title="如何使用本教程"></a>如何使用本教程</h3><p>别被下面那些复杂的表达式吓倒,只要跟着我一步一步来,你会发现正则表达式其实并没有想像中的那么困难。当然,如果你看完了这篇教程之后,发现自己明白了很多,却又几乎什么都记不得,那也是很正常的——我认为,没接触过正则表达式的人在看完这篇教程后,能把提到过的语法记住80%以上的可能性为零。这里只是让你明白基本的原理,以后你还需要多练习,多使用,才能熟练掌握正则表达式。</p><p>除了作为入门教程之外,本文还试图成为可以在日常工作中使用的正则表达式语法参考手册。就作者本人的经历来说,这个目标还是完成得不错的——你看,我自己也没能把所有的东西记下来,不是吗?</p><p>本文介绍的大部分正则语法,在不同的正则表达式引擎中都可以使用,但也有一些会有所差异。本文介绍的是 .Net 下的正则表达式,其它环境下的具体情况可以在读完本文后去参考官方文档,或者查看正则表达式引擎特性对比。</p><h3 id="正则表达式到底是什么东西?"><a href="#正则表达式到底是什么东西?" class="headerlink" title="正则表达式到底是什么东西?"></a>正则表达式到底是什么东西?</h3><p>在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要。正则表达式就是用于描述这些规则的工具。换句话说,正则表达式就是记录文本规则的代码。</p><p>很可能你使用过Windows/Dos下用于文件查找的通配符(wildcard),也就是<em>和?。如果你想查找某个目录下的所有的Word文档的话,你会搜索</em>.doc。在这里,*会被解释成任意的字符串。和通配符类似,正则表达式也是用来进行文本匹配的工具,只不过比起通配符,它能更精确地描述你的需求——当然,代价就是更复杂——比如你可以编写一个正则表达式,用来查找所有以0开头,后面跟着2-3个数字,然后是一个连字号“-”,最后是7或8位数字的字符串(像010-12345678或0376-7654321)。</p><h3 id="入门"><a href="#入门" class="headerlink" title="入门"></a>入门</h3><p>学习正则表达式的最好方法是从例子开始,理解例子之后再自己对例子进行修改,实验。下面给出了不少简单的例子,并对它们作了详细的说明。</p><p>假设你在一篇英文小说里查找hi,你可以使用正则表达式hi。</p><p>这几乎是最简单的正则表达式了,它可以精确匹配这样的字符串:<strong>由两个字符组成,前一个字符是h,后一个是i</strong>。通常,处理正则表达式的工具会提供一个忽略大小写的选项,如果选中了这个选项,它可以匹配hi,HI,Hi,hI这四种情况中的任意一种。</p><p>不幸的是,很多单词里包含hi这两个连续的字符,比如him,history,high等等。用hi来查找的话,这里边的hi也会被找出来。如果要精确地查找hi这个单词的话,我们应该使用<code>\bhi\b</code>。</p><p><strong>\b</strong>是正则表达式规定的一个特殊代码(好吧,某些人叫它<strong>元字符,metacharacter</strong>),代表着单词的开头或结尾,也就是单词的分界处。虽然通常英文的单词是由空格,标点符号或者换行来分隔的,但是\b并不匹配这些单词分隔字符中的任何一个,它只匹配一个位置。</p><p>假如你要找的是hi后面不远处跟着一个Lucy,你应该用\bhi\b.*\bLucy\b。</p><p>这里,.是另一个元字符,匹配除了换行符以外的任意字符。<em>同样是元字符,不过它代表的不是字符,也不是位置,而是数量——它指定</em>前边的内容可以连续重复使用任意次以使整个表达式得到匹配。因此,.*连在一起就意味着任意数量的不包含换行的字符。现在\bhi\b.*\bLucy\b的意思就很明显了:先是一个单词hi,然后是任意个任意字符(但不能是换行),最后是Lucy这个单词。</p><p>如果同时使用其它元字符,我们就能构造出功能更强大的正则表达式。比如下面这个例子:</p><p>0\d\d-\d\d\d\d\d\d\d\d匹配这样的字符串:以0开头,然后是两个数字,然后是一个连字号“-”,最后是8个数字(也就是中国的电话号码。当然,这个例子只能匹配区号为3位的情形)。</p><p>这里的\d是个新的元字符,匹配一位数字(0,或1,或2,或……)。-不是元字符,只匹配它本身——连字符(或者减号,或者中横线,或者随你怎么称呼它)。</p><p>为了避免那么多烦人的重复,我们也可以这样写这个表达式:**0\d{2}-\d{8}**。这里\d后面的{2}({8})的意思是前面\d必须连续重复匹配2次(8次)。</p><h3 id="元字符"><a href="#元字符" class="headerlink" title="元字符"></a>元字符</h3><p>现在你已经知道几个很有用的元字符了,如<strong>\b,.,*</strong>,还有\d.正则表达式里还有更多的元字符,比如\s匹配任意的空白符,包括空格,制表符(Tab),换行符,中文全角空格等。\w匹配字母或数字或下划线或汉字等。</p><p>下面来看看更多的例子:</p><p><strong>\ba\w*\b</strong>匹配以字母a开头的单词——先是某个单词开始处(\b),然后是字母a,然后是任意数量的字母或数字(\w*),最后是单词结束处(\b)。</p><p>*<em>\d+**匹配1个或更多连续的数字。这里的+是和</em>类似的元字符,不同的是*匹配重复任意次(可能是0次),而+则匹配重复1次或更多次。 </p><p><strong>\b\w{6}\b</strong> 匹配刚好6个字符的单词。</p><h4 id="表1-常用的元字符"><a href="#表1-常用的元字符" class="headerlink" title="表1.常用的元字符"></a>表1.常用的元字符</h4><table><thead><tr><th>代码</th><th>说明</th></tr></thead><tbody><tr><td>.</td><td>匹配除换行符以外的任意字符</td></tr><tr><td>\w</td><td>匹配字母或数字或下划线或汉字</td></tr><tr><td>\s</td><td>匹配任意的空白符</td></tr><tr><td>\d</td><td>匹配数字</td></tr><tr><td>\b</td><td>匹配单词的开始或结束</td></tr><tr><td>^</td><td>匹配字符串的开始</td></tr><tr><td>$</td><td>匹配字符串的结束</td></tr></tbody></table><p>元字符^(和数字6在同一个键位上的符号)和$都匹配一个位置,这和\b有点类似。^匹配你要用来查找的字符串的开头,$匹配结尾。这两个代码在验证输入的内容时非常有用,比如一个网站如果要求你填写的QQ号必须为5位到12位数字时,可以使用:^\d{5,12}$。</p><p>这里的{5,12}和前面介绍过的{2}是类似的,只不过{2}匹配只能不多不少重复2次,{5,12}则是重复的次数不能少于5次,不能多于12次,否则都不匹配。</p><p>因为使用了^和$,所以输入的整个字符串都要用来和\d{5,12}来匹配,也就是说整个输入必须是5到12个数字,因此如果输入的QQ号能匹配这个正则表达式的话,那就符合要求了。 </p><p>和忽略大小写的选项类似,有些正则表达式处理工具还有一个处理多行的选项。如果选中了这个选项,^和$的意义就变成了匹配行的开始处和结束处。</p><h3 id="字符转义"><a href="#字符转义" class="headerlink" title="字符转义"></a>字符转义</h3><p>如果你想查找元字符本身的话,比如你查找.,或者*,就出现了问题:你没办法指定它们,因为它们会被解释成别的意思。这时你就得使用\来取消这些字符的特殊意义。因此,你应该使用.和*。当然,要查找\本身,你也得用.</p><p>例如:deerchao.cn匹配deerchao.cn,C:\Windows匹配C:\Windows。</p><h3 id="重复"><a href="#重复" class="headerlink" title="重复"></a>重复</h3><p>你已经看过了前面的*,+,{2},{5,12}这几个匹配重复的方式了。下面是正则表达式中所有的限定符(指定数量的代码,例如*,{5,12}等):</p><h4 id="表2-常用的限定符"><a href="#表2-常用的限定符" class="headerlink" title="表2.常用的限定符"></a>表2.常用的限定符</h4><table><thead><tr><th>代码/语法</th><th>说明</th></tr></thead><tbody><tr><td>*</td><td>重复零次或更多次</td></tr><tr><td>+</td><td>重复一次或更多次</td></tr><tr><td>?</td><td>重复零次或一次</td></tr><tr><td>{n}</td><td>重复n次</td></tr><tr><td>{n,}</td><td>重复n次或更多次</td></tr><tr><td>{n,m}</td><td>重复n到m次</td></tr></tbody></table><p>下面是一些使用重复的例子:</p><p>Windows\d+匹配Windows后面跟1个或更多数字</p><p>^\w+匹配一行的第一个单词(或整个字符串的第一个单词,具体匹配哪个意思得看选项设置)</p><h3 id="字符类"><a href="#字符类" class="headerlink" title="字符类"></a>字符类</h3><p>要想查找数字,字母或数字,空白是很简单的,因为已经有了对应这些字符集合的元字符,但是如果你想匹配没有预定义元字符的字符集合(比如元音字母a,e,i,o,u),应该怎么办?</p><p>很简单,你只需要在方括号里列出它们就行了,像[aeiou]就匹配任何一个英文元音字母,[.?!]匹配标点符号(.或?或!)。</p><p>我们也可以轻松地指定一个字符范围,像[0-9]代表的含意与\d就是完全一致的:一位数字;同理[a-z0-9A-Z_]也完全等同于\w(如果只考虑英文的话)。</p><p>下面是一个更复杂的表达式:(?0\d{2}[) -]?\d{8}。</p><p>这个表达式可以匹配几种格式的电话号码,像(010)88886666,或022-22334455,或02912345678等。我们对它进行一些分析吧:首先是一个转义字符(,它能出现0次或1次(?),然后是一个0,后面跟着2个数字(\d{2}),然后是)或-或空格中的一个,它出现1次或不出现(?),最后是8个数字(\d{8})。</p><h3 id="分枝条件"><a href="#分枝条件" class="headerlink" title="分枝条件"></a>分枝条件</h3><p>不幸的是,刚才那个表达式也能匹配010)12345678或(022-87654321这样的“不正确”的格式。要解决这个问题,我们需要用到分枝条件。正则表达式里的分枝条件指的是有几种规则,如果满足其中任意一种规则都应该当成匹配,具体方法是用|把不同的规则分隔开。听不明白?没关系,看例子:</p><p>0\d{2}-\d{8}|0\d{3}-\d{7}这个表达式能匹配两种以连字号分隔的电话号码:一种是三位区号,8位本地号(如010-12345678),一种是4位区号,7位本地号(0376-2233445)。</p><p>(0\d{2})[- ]?\d{8}|0\d{2}[- ]?\d{8}这个表达式匹配3位区号的电话号码,其中区号可以用小括号括起来,也可以不用,区号与本地号间可以用连字号或空格间隔,也可以没有间隔。你可以试试用分枝条件把这个表达式扩展成也支持4位区号的。 </p><p>\d{5}-\d{4}|\d{5}这个表达式用于匹配美国的邮政编码。美国邮编的规则是5位数字,或者用连字号间隔的9位数字。之所以要给出这个例子是因为它能说明一个问题:<strong>使用分枝条件时,要注意各个条件的顺序</strong>。如果你把它改成\d{5}|\d{5}-\d{4}的话,那么就只会匹配5位的邮编(以及9位邮编的前5位)。原因是匹配分枝条件时,将会从左到右地测试每个条件,如果满足了某个分枝的话,就不会去再管其它的条件了。 </p><h3 id="分组"><a href="#分组" class="headerlink" title="分组"></a>分组</h3><p>我们已经提到了怎么重复单个字符(直接在字符后面加上限定符就行了);但如果想要重复多个字符又该怎么办?你可以用小括号来指定子表达式(也叫做分组),然后你就可以指定这个子表达式的重复次数了,你也可以对子表达式进行其它一些操作(后面会有介绍)。</p><p>(\d{1,3}.){3}\d{1,3}是一个简单的IP地址匹配表达式。要理解这个表达式,请按下列顺序分析它:\d{1,3}匹配1到3位的数字,(\d{1,3}.){3}匹配三位数字加上一个英文句号(这个整体也就是这个分组)重复3次,最后再加上一个一到三位的数字(\d{1,3})。</p><p>不幸的是,它也将匹配256.300.888.999这种不可能存在的IP地址。如果能使用算术比较的话,或许能简单地解决这个问题,但是正则表达式中并不提供关于数学的任何功能,所以只能使用冗长的分组,选择,字符类来描述一个正确的IP地址:((2[0-4]\d|25[0-5]|[01]?\d\d?).){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)。</p><p>理解这个表达式的关键是理解2[0-4]\d|25[0-5]|[01]?\d\d?,这里我就不细说了,你自己应该能分析得出来它的意义。</p><h3 id="反义"><a href="#反义" class="headerlink" title="反义"></a>反义</h3><p>有时需要查找不属于某个能简单定义的字符类的字符。比如想查找除了数字以外,其它任意字符都行的情况,这时需要用到反义:</p><h4 id="表3-常用的反义代码"><a href="#表3-常用的反义代码" class="headerlink" title="表3.常用的反义代码"></a>表3.常用的反义代码</h4><table><thead><tr><th>代码/语法</th><th>说明</th></tr></thead><tbody><tr><td>\W</td><td>匹配任意不是字母,数字,下划线,汉字的字符</td></tr><tr><td>\S</td><td>匹配任意不是空白符的字符</td></tr><tr><td>\D</td><td>匹配任意非数字的字符</td></tr><tr><td>\B</td><td>匹配不是单词开头或结束的位置</td></tr><tr><td>[^x]</td><td>匹配除了x以外的任意字符</td></tr><tr><td>[^aeiou]</td><td>匹配除了aeiou这几个字母以外的任意字符</td></tr></tbody></table><p>例子:\S+匹配不包含空白符的字符串。</p><p><a[^>]+>匹配用尖括号括起来的以a开头的字符串。</p><h3 id="后向引用"><a href="#后向引用" class="headerlink" title="后向引用"></a>后向引用</h3><p>使用小括号指定一个子表达式后,<strong>匹配这个子表达式的文本</strong>(也就是此分组捕获的内容)可以在表达式或其它程序中作进一步的处理。默认情况下,每个分组会自动拥有一个组号,规则是:从左向右,以分组的左括号为标志,第一个出现的分组的组号为1,第二个为2,以此类推。</p><p>后向引用用于重复搜索前面某个分组匹配的文本。例如,\1代表分组1匹配的文本。难以理解?请看示例:</p><p>\b(\w+)\b\s+\1\b可以用来匹配重复的单词,像go go, 或者kitty kitty。这个表达式首先是一个单词,也就是单词开始处和结束处之间的多于一个的字母或数字(\b(\w+)\b),这个单词会被捕获到编号为1的分组中,然后是1个或几个空白符(\s+),最后是分组1中捕获的内容(也就是前面匹配的那个单词)(\1)。</p><p>你也可以自己指定子表达式的组名。要指定一个子表达式的组名,请使用这样的语法:(?\w+)(或者把尖括号换成’也行:(?’Word’\w+)),这样就把\w+的组名指定为Word了。要反向引用这个分组捕获的内容,你可以使用\k,所以上一个例子也可以写成这样:\b(?\w+)\b\s+\k\b。</p><p>使用小括号的时候,还有很多特定用途的语法。下面列出了最常用的一些:</p><h4 id="表4-常用分组语法"><a href="#表4-常用分组语法" class="headerlink" title="表4.常用分组语法"></a>表4.常用分组语法</h4><table><thead><tr><th>分类</th><th>代码/语法</th><th>说明</th></tr></thead><tbody><tr><td>捕获</td><td>(exp)</td><td>匹配exp,并捕获文本到自动命名的组里</td></tr><tr><td>(?exp)</td><td>匹配exp,并捕获文本到名称为name的组里,也可以写成(?’name’exp)</td><td></td></tr><tr><td>(?:exp)</td><td>匹配exp,不捕获匹配的文本,也不给此分组分配组号</td><td></td></tr><tr><td>零宽断言</td><td>(?=exp)</td><td>匹配exp前面的位置</td></tr><tr><td>(?<=exp)</td><td>匹配exp后面的位置</td><td></td></tr><tr><td>(?!exp)</td><td>匹配后面跟的不是exp的位置</td><td></td></tr><tr><td>(?<!exp)</td><td>匹配前面不是exp的位置</td><td></td></tr><tr><td>注释</td><td>(?#comment)</td><td>这种类型的分组不对正则表达式的处理产生任何影响,用于提供注释让人阅读</td></tr></tbody></table><table><thead><tr><th>注释</th><th>(?#comment)</th><th>这种类型的分组不对正则表达式的处理产生任何影响,用于提供注释让人阅读</th></tr></thead><tbody><tr><td></td><td></td><td></td></tr></tbody></table><p>我们已经讨论了前两种语法。第三个(?:exp)不会改变正则表达式的处理方式,只是这样的组匹配的内容不会像前两种那样被捕获到某个组里面,也不会拥有组号。“我为什么会想要这样做?”——好问题,你觉得为什么呢?</p><h3 id="零宽断言"><a href="#零宽断言" class="headerlink" title="零宽断言"></a>零宽断言</h3><p>接下来的四个用于查找在某些内容(但并不包括这些内容)之前或之后的东西,也就是说它们像\b,^,$那样用于指定一个位置,这个位置应该满足一定的条件(即断言),因此它们也被称为零宽断言。最好还是拿例子来说明吧: </p><p>(?=exp)也叫零宽度正预测先行断言,它断言自身出现的位置的后面能匹配表达式exp。比如\b\w+(?=ing\b),匹配以ing结尾的单词的前面部分(除了ing以外的部分),如查找I’m singing while you’re dancing.时,它会匹配sing和danc。</p><p>(?<=exp)也叫零宽度正回顾后发断言,它断言自身出现的位置的前面能匹配表达式exp。比如(?<=\bre)\w+\b会匹配以re开头的单词的后半部分(除了re以外的部分),例如在查找reading a book时,它匹配ading。</p><p>假如你想要给一个很长的数字中每三位间加一个逗号(当然是从右边加起了),你可以这样查找需要在前面和里面添加逗号的部分:((?<=\d)\d{3})+\b,用它对1234567890进行查找时结果是234567890。</p><p>下面这个例子同时使用了这两种断言:(?<=\s)\d+(?=\s)匹配以空白符间隔的数字(再次强调,不包括这些空白符)。</p><h3 id="负向零宽断言"><a href="#负向零宽断言" class="headerlink" title="负向零宽断言"></a>负向零宽断言</h3><p>前面我们提到过怎么查找<strong>不是某个字符或不在某个字符类里</strong>的字符的方法(反义)。但是如果我们只是想要<strong>确保某个字符没有出现,但并不想去匹配它</strong>时怎么办?例如,如果我们想查找这样的单词–它里面出现了字母q,但是q后面跟的不是字母u,我们可以尝试这样: </p><p>\b\w<em>q[^u]\w</em>\b匹配包含<strong>后面不是字母u的字母q</strong>的单词。但是如果多做测试(或者你思维足够敏锐,直接就观察出来了),你会发现,如果q出现在单词的结尾的话,像<strong>Iraq</strong>,<strong>Benq</strong>,这个表达式就会出错。这是因为[^u]总要匹配一个字符,所以如果q是单词的最后一个字符的话,后面的[^u]将会匹配q后面的单词分隔符(可能是空格,或者是句号或其它的什么),后面的\w<em>\b将会匹配下一个单词,于是\b\w</em>q[^u]\w<em>\b就能匹配整个Iraq fighting。负向零宽断言能解决这样的问题,因为它只匹配一个位置,并不<strong>消费</strong>任何字符。现在,我们可以这样来解决这个问题:\b\w</em>q(?!u)\w*\b。</p><p>零宽度负预测先行断言(?!exp),断言此位置的后面不能匹配表达式exp。例如:\d{3}(?!\d)匹配三位数字,而且这三位数字的后面不能是数字;\b((?!abc)\w)+\b匹配不包含连续字符串abc的单词。</p><p>同理,我们可以用(?<!exp),零宽度负回顾后发断言来断言此位置的前面不能匹配表达式exp:(?<![a-z])\d{7}匹配前面不是小写字母的七位数字。</p><p>一个更复杂的例子:(?<=<(\w+)>).<em>(?=</\1>)匹配不包含属性的简单HTML标签内里的内容。(?<=<(\w+)>)指定了这样的前缀:被尖括号括起来的单词(比如可能是**),然后是.****</em>(任意的字符串),最后是一个后缀(?=</\1>)。注意后缀里的/,它用到了前面提过的字符转义;\1则是一个反向引用,引用的正是捕获的第一组,前面的(\w+)匹配的内容,这样如果前缀实际上是*<em>的话,后缀就是*</em>了。整个表达式匹配的是*<em>和*</em>之间的内容(再次提醒,不包括前缀和后缀本身)。** </p><p><strong>注释小括号的另一种用途是通过语法(?#comment)来包含注释。例如:2[0-4]\d(?#200-249)|25<a href="https://izyq.github.io/2020/07/31/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F30min%E5%85%A5%E9%97%A8/#250-255">0-5</a>|[01]?\d\d?(?#0-199)。 要包含注释的话,最好是启用“忽略模式里的空白符”选项,这样在编写表达式时能任意的添加空格,Tab,换行,而实际使用时这些都将被忽略。启用这个选项后,在#后面到这一行结束的所有文本都将被当成注释忽略掉。例如,我们可以前面的一个表达式写成这样:</strong> </p><pre class="line-numbers language-none"><code class="language-none">(?<= # 断言要匹配的文本的前缀<(\w+)> # 查找尖括号括起来的内容 # (即HTML/XML标签)) # 前缀结束.* # 匹配任意文本(?= # 断言要匹配的文本的后缀<\/\1> # 查找尖括号括起来的内容 # 查找尖括号括起来的内容) # 后缀结束<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="贪婪与懒惰"><a href="#贪婪与懒惰" class="headerlink" title="贪婪与懒惰"></a>贪婪与懒惰</h3><p><strong>当正则表达式中包含能接受重复的限定符时,通常的行为是(在使整个表达式能得到匹配的前提下)匹配\</strong>尽可能多*<em>的字符。以这个表达式为例:a.\</em>b,它将会匹配最长的以a开始,以b结束的字符串。如果用它来搜索aabab的话,它会匹配整个字符串aabab。这被称为贪婪匹配。 有时,我们更需要懒惰匹配,也就是匹配*<em>尽可能少*</em>的字符。前面给出的限定符都可以被转化为懒惰匹配模式,只要在它后面加上一个问号?。这样.*?就意味着匹配任意数量的重复,但是在能使整个匹配成功的前提下使用最少的重复。现在看看懒惰版的例子吧: a.*?b匹配最短的,以a开始,以b结束的字符串。如果把它应用于aabab的话,它会匹配aab(第一到第三个字符)和ab(第四到第五个字符)。 **</p><p><strong>表5.懒惰限定符</strong></p><table><thead><tr><th><strong>代码/语法</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td>*<strong>?</strong></td><td><strong>重复任意次,但尽可能少重复</strong></td></tr><tr><td><strong>+?</strong></td><td><strong>重复1次或更多次,但尽可能少重复</strong></td></tr><tr><td><strong>??</strong></td><td><strong>重复0次或1次,但尽可能少重复</strong></td></tr><tr><td><strong>{n,m}?</strong></td><td><strong>重复n到m次,但尽可能少重复</strong></td></tr><tr><td><strong>{n,}?</strong></td><td><strong>重复n次以上,但尽可能少重复</strong></td></tr></tbody></table><h3 id="处理选项"><a href="#处理选项" class="headerlink" title="处理选项"></a>处理选项</h3><p><strong>上面介绍了几个选项如忽略大小写,处理多行等,这些选项能用来改变处理正则表达式的方式。下面是.Net中常用的正则表达式选项:</strong></p><h4 id="表6-常用的处理选项"><a href="#表6-常用的处理选项" class="headerlink" title="表6.常用的处理选项"></a>表6.常用的处理选项</h4><table><thead><tr><th><strong>名称</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td><strong>IgnoreCase(忽略大小写)</strong></td><td><strong>匹配时不区分大小写。</strong></td></tr><tr><td><strong>Multiline(多行模式)</strong></td><td><strong>更改^和$的含义,使它们分别在任意一行的行首和行尾匹配,而不仅仅在整个字符串的开头和结尾匹配。(在此模式下,$的精确含意是:匹配\n之前的位置以及字符串结束前的位置.)</strong></td></tr><tr><td><strong>Singleline(单行模式)</strong></td><td><strong>更改.的含义,使它与每一个字符匹配(包括换行符\n)。</strong></td></tr><tr><td><strong>IgnorePatternWhitespace(忽略空白)</strong></td><td><strong>忽略表达式中的非转义空白并启用由#标记的注释。</strong></td></tr><tr><td><strong>ExplicitCapture(显式捕获)</strong></td><td><strong>仅捕获已被显式命名的组。</strong></td></tr></tbody></table><p><strong>一个经常被问到的问题是:是不是只能同时使用多行模式和单行模式中的一种?答案是:不是。这两个选项之间没有任何关系,除了它们的名字比较相似(以至于让人感到疑惑)以外。事实上,为了避免混淆,在最新的 JavaScript 中,单行模式其实名叫 dotAll,意为点可以匹配所有字符,然而在指定该选项时,用的还是 Singleline 的首字母 s.</strong></p><h2 id="平衡组-递归匹配"><a href="#平衡组-递归匹配" class="headerlink" title="平衡组/递归匹配"></a>平衡组/递归匹配</h2><p>有时我们需要匹配像( 100 * ( 50 + 15 ) )这样的可嵌套的层次性结构,这时简单地使用(.+)则只会匹配到最左边的左括号和最右边的右括号之间的内容(这里我们讨论的是贪婪模式,懒惰模式也有下面的问题)。假如原来的字符串里的左括号和右括号出现的次数不相等,比如( 5 / ( 3 + 2 ) ) ),那我们的匹配结果里两者的个数也不会相等。有没有办法在这样的字符串里匹配到最长的,配对的括号之间的内容呢? </p><p>为了避免(和(把你的大脑彻底搞糊涂,我们还是用尖括号代替圆括号吧。现在我们的问题变成了如何把xx <aa <bbb> <bbb> aa> yy这样的字符串里,最长的配对的尖括号内的内容捕获出来?</p><p>这里需要用到以下的语法构造:</p><ul><li>(?’group’) 把捕获的内容命名为group,并压入堆栈(Stack)</li><li>(?’-group’) 从堆栈上弹出最后压入堆栈的名为group的捕获内容,如果堆栈本来为空,则本分组的匹配失败</li><li>(?(group)yes|no) 如果堆栈上存在以名为group的捕获内容的话,继续匹配yes部分的表达式,否则继续匹配no部分</li><li>(?!) 零宽负向先行断言,由于没有后缀表达式,试图匹配总是失败</li></ul><p>我们需要做的是每碰到了左括号,就在压入一个”Open”,每碰到一个右括号,就弹出一个,到了最后就看看堆栈是否为空--如果不为空那就证明左括号比右括号多,那匹配就应该失败。正则表达式引擎会进行回溯(放弃最前面或最后面的一些字符),尽量使整个表达式得到匹配。 </p><pre class="line-numbers language-none"><code class="language-none">< #最外层的左括号 [^<>]* #它后面非括号的内容 ( ( (?'Open'<) #左括号,压入"Open" [^<>]* #左括号后面的内容 )+ ( (?'-Open'>) #右括号,弹出一个"Open" [^<>]* #右括号后面的内容 )+ )* (?(Open)(?!)) #最外层的右括号前检查 #若还有未弹出的"Open" #则匹配失败> #最外层的右括号<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>平衡组的一个最常见的应用就是匹配HTML,下面这个例子可以匹配嵌套的<div>标签:<code><div[^>]\*>[^<>]\*(((?'Open'<div[^>]\*>)[^<>]\*)+((?'-Open'</div>)[^<>]\*)+)\*(?(Open)(?!))</div>.</code>** </p><h2 id="还有些什么东西没提到"><a href="#还有些什么东西没提到" class="headerlink" title="还有些什么东西没提到"></a>还有些什么东西没提到</h2><p>上边已经描述了构造正则表达式的大量元素,但是还有很多没有提到的东西。下面是一些未提到的元素的列表,包含语法和简单的说明。你可以在网上找到更详细的参考资料来学习它们–当你需要用到它们的时候。如果你安装了MSDN Library,你也可以在里面找到.Net下正则表达式详细的文档。这里的介绍很简略,如果你需要更详细的信息,而又没有在电脑上安装MSDN Library,可以查看<a href="http://msdn.microsoft.com/zh-cn/library/az24scfc.aspx">关于正则表达式语言元素的MSDN在线文档</a>。</p><table><thead><tr><th>代码/语法</th><th>说明</th></tr></thead><tbody><tr><td>\a</td><td>报警字符(打印它的效果是电脑嘀一声)</td></tr><tr><td>\b</td><td>通常是单词分界位置,但如果在字符类里使用代表退格</td></tr><tr><td>\t</td><td>制表符,Tab</td></tr><tr><td>\r</td><td>回车</td></tr><tr><td>\v</td><td>竖向制表符</td></tr><tr><td>\f</td><td>换页符</td></tr><tr><td>\n</td><td>换行符</td></tr><tr><td>\e</td><td>Escape</td></tr><tr><td>\0nn</td><td>ASCII代码中八进制代码为nn的字符</td></tr><tr><td>\xnn</td><td>ASCII代码中十六进制代码为nn的字符</td></tr><tr><td>\unnnn</td><td>Unicode代码中十六进制代码为nnnn的字符</td></tr><tr><td>\cN</td><td>ASCII控制字符。比如\cC代表Ctrl+C</td></tr><tr><td>\A</td><td>字符串开头(类似^,但不受处理多行选项的影响)</td></tr><tr><td>\Z</td><td>字符串结尾或行尾(不受处理多行选项的影响)</td></tr><tr><td>\z</td><td>字符串结尾(类似$,但不受处理多行选项的影响)</td></tr><tr><td>\G</td><td>当前搜索的开头</td></tr><tr><td>\p{name}</td><td>Unicode中命名为name的字符类,例如\p{IsGreek}</td></tr><tr><td>(?>exp)</td><td>贪婪子表达式</td></tr><tr><td>(?<x>-<y>exp)</td><td>平衡组</td></tr><tr><td>(?im-nsx:exp)</td><td>在子表达式exp中改变处理选项</td></tr><tr><td>(?im-nsx)</td><td>为表达式后面的部分改变处理选项</td></tr><tr><td>(?(exp)yes|no)</td><td>把exp当作零宽正向先行断言,如果在这个位置能匹配,使用yes作为此组的表达式;否则使用no</td></tr><tr><td>(?(exp)yes)</td><td>同上,只是使用空表达式作为no</td></tr><tr><td>(?(name)yes|no)</td><td>如果命名为name的组捕获到了内容,使用yes作为表达式;否则使用no</td></tr><tr><td>(?(name)yes)</td><td>同上,只是使用空表达式作为no</td></tr></tbody></table>]]></content>
<categories>
<category> Others </category>
</categories>
<tags>
<tag> 正则表达式 </tag>
</tags>
</entry>
<entry>
<title>Hexo deploy 时免输用户名密码</title>
<link href="2020/07/30/deploy/"/>
<url>2020/07/30/deploy/</url>
<content type="html"><![CDATA[<h3 id="首先关于Hexo-admin"><a href="#首先关于Hexo-admin" class="headerlink" title="首先关于Hexo-admin"></a>首先关于Hexo-admin</h3><p>使用了一位大佬修改后的<a href="https://blog.csdn.net/nineya_com/article/details/103384546">Hexo-admin</a>,解决了windows系统插入图片失败问题解决,通过修改源码完美解决,hexo-admin汉化,以及添加按文章存储图片功能(方便管理)</p><h3 id="回归正题"><a href="#回归正题" class="headerlink" title="回归正题"></a>回归正题</h3><ul><li>设置 SSH 使用 hexo deploy 时免输用户名密码</li></ul><h4 id="生成-SSH-密钥"><a href="#生成-SSH-密钥" class="headerlink" title="生成 SSH 密钥"></a>生成 SSH 密钥</h4><p>右键鼠标任意位置打开 <strong>Git Bash Here</strong>,然后输入以下命令</p><pre class="line-numbers language-none"><code class="language-none">cd ~/.ssh<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>使用 <strong>ssh-keygen</strong> 生成密钥</p><pre class="line-numbers language-none"><code class="language-none">ssh-keygen -t rsa -C "[email protected]"Generating public/private rsa key pair.Enter file in which to save the key (/home/you/.ssh/id_rsa):<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>使用默认的文件名直接enter,接下来显示如下</p><pre class="line-numbers language-none"><code class="language-none">Enter passphrase (empty for no passphrase): [Type a passphrase]Enter same passphrase again: [Type passphrase again]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><em>按提示输入密码即可(简化流程的话在键入命令 ssh-keygen -t rsa -C “<a href="mailto:[email protected]">[email protected]</a>“ 以后的三次提示输入都可以直接回车跳过)。</em></p><p><strong>密钥生成成功</strong></p><pre class="line-numbers language-none"><code class="language-none">Your identification has been saved in /home/you/.ssh/id_rsa.Your public key has been saved in /home/you/.ssh/id_rsa.pub.The key fingerprint is:…………………此处是密钥内容…………………… [email protected]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><h4 id="设置-Github-项目的-Deploy-keys"><a href="#设置-Github-项目的-Deploy-keys" class="headerlink" title="设置 Github 项目的 Deploy keys"></a>设置 Github 项目的 Deploy keys</h4><p>以我的博客为例,在 izyq.github.io 的首页菜单栏中点击 Settings –> Deploy keys –> Add deploy key,然后将生成的 id_rsa.pub 中的内容全选复制到 key 输入框中,然后点击 Add key 完成添加公钥。</p><p>接下来测试配置是否成功</p><pre class="line-numbers language-none"><code class="language-none">$ ssh -T [email protected]<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>出现以下内容即表示配置完成并且成功</p><pre class="line-numbers language-none"><code class="language-none">Hi username! You've successfully authenticated, but GitHub does notprovide shell access.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><h4 id="修改hexo根目录的配置文件"><a href="#修改hexo根目录的配置文件" class="headerlink" title="修改hexo根目录的配置文件"></a>修改hexo根目录的配置文件</h4><p>修改_config.yml 中的deploy属性,将repo改为<br><strong><a href="mailto:[email protected]">[email protected]</a>:USERNAME/REPOSITORY.git</strong><br>如下</p><pre class="line-numbers language-none"><code class="language-none">deploy: type: git repo: [email protected]:izyq/izyq.github.io.git branch: master<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p>这个时候再尝试了 <code>$ hexo deploy</code> 就成功了,就不用老是输入密码了!</p>]]></content>
<categories>
<category> 折腾 </category>
</categories>
<tags>
<tag> Hexo </tag>
</tags>
</entry>
<entry>
<title>P775TM刷BIOS EC</title>
<link href="2020/07/17/bios/"/>
<url>2020/07/17/bios/</url>
<content type="html"><![CDATA[<h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2><blockquote><p>最近打算换9代U了,是时候升级一下BIOS了,反正在寝室隔离搞完半天学习想休息一下,也没事做,开始折腾起来哈哈<br>这次时想把I58400升级为i9-9900es <em>(因为穷)</em>.<br><code>在d大的包里提供两种刷入方法,一种是dos,一种是win,win这边我打开那个软件第一步就不行,所以只能尝试第二种方法,Dos模式刷入,当然这种方法也更稳定,也是d大更推荐的方法</code></p></blockquote><p> 作者提示:_点我一键刷黑.bat或_现在就刷黑.bat执行之后如果出现红字说明你的_说明没读5遍没资格点.exe执行失败了,请多次尝试,如果多次尝试均失败说明你这个机器不兼容,请参考上面的情况二。<br> _点我一键刷黑.bat执行之后如果出现红字那么你执行_现在就刷黑.bat也会出现红字,这是正常的!红字就是刷不了,失败了,请参考上面的情况二。<br>如果执行_点我一键刷黑.bat或_现在就刷黑.bat之后,走进度百分比之后出现红字报错,一定不要关机!一定不要关机!一定不要关机!请重新执行一次,一次不行就两次,两次不行就三次,直到提示绿字操作成功!<br>这种情况贸然关机或重启一定会黑!这种情况贸然关机或重启一定会黑!这种情况贸然关机或重启一定会黑!<br>提示黄字“GbE Region does not exist.”是正常的,因为准系统的BIOS本来就没有“GbE Region”,忽略即可!</p><h3 id="准备"><a href="#准备" class="headerlink" title="准备"></a>准备</h3><ul><li><p>首先把安全软件卸了,防止捣乱</p></li><li><p>如果你用的是Win8/8.1/10的操作系统,请禁用休眠!禁用休眠!管理员身份命令行执行“<code>powercfg -h off</code>”</p></li><li><p>将U盘或者移动硬盘格式化为FAT32(只能是FAT32而且只能有一个分区),把EFI文件夹复制到U盘根目录!根目录!根目录!确保U盘打开就能看到EFI文件夹!</p></li><li><p>然后把你要刷的BIOS文件改名为BIOS.BIN(注意扩展名也要改,原来是ROM,现在改成BIN),放入EFI/BOOT文件夹内。</p></li><li><p>重启按F2进入BIOS,寻找下列选项并修改</p><ul><li>BIOS主界面->顶部的Boot->UEFI Settings->UEFI Boot->Enabled</li><li>BIOS主界面->顶部的Security->Secure Boot->Disabled</li></ul></li><li><p>修改好之后,插入U盘,蓝天机型按F4,回车保存,这里会自动重启,我们需要再次进入BIOS,按F7进入启动设备的菜单,选中后按回车从你的U盘启动,进入 EFI Shell 命令行,提示符闪烁就证明准备工作做完了。</p><h3 id="开刷"><a href="#开刷" class="headerlink" title="开刷"></a>开刷</h3></li><li><p>1.输入G回车</p></li></ul><blockquote><p><strong>注意:</strong> 输入G回车之后会自动重启,如果没有自动重启说明你这个机器不兼容。<br>这次重启黑屏的时间会比较长,<code>我大约等了15s的样子</code>这时候风扇可能会满速运转,算是进入强冷模式了。<br>这是正常的!无需在意,操作完成后就会恢复,如果害怕你可以重启它也会自己恢复。<br>只要不是命令执行时的强制重启,都没有任何危险性!</p></blockquote><ul><li>继续按F7(蓝天),选择U盘启动,再来进入下一步操作</li><li>2.备份<br>A回车C回车</li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/bio/pasted-1.png" alt="奔跑博客"></p><ul><li>3.刷入<br>D回车F回车</li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/bio/pasted-2.png" alt="奔跑博客"></p><p>看到successfel就说明刷入成功了<br>接着按F回车,执行第四步</p><ul><li>4.直接拔掉AC电源给机器断电(这步很重要,如果不照做99%的人会刷黑)<br>然后装回硬盘、电池、插回AC电源开机,至此完成刷写过程</li></ul><p><img src="https://cdn.jsdelivr.net/gh/izyq/izyq.github.io@master/2021/01/23/bio/pasted-3.png" alt="奔跑博客"></p>]]></content>
<categories>
<category> 折腾 </category>
</categories>
<tags>
<tag> BIOS </tag>
<tag> P775TM </tag>
</tags>
</entry>
<entry>
<title>CUPKNotice部署到Linux上</title>
<link href="2020/07/16/cupk/"/>
<url>2020/07/16/cupk/</url>
<content type="html"><![CDATA[<h2 id="安装Python3-7-并解决ssl问题"><a href="#安装Python3-7-并解决ssl问题" class="headerlink" title="安装Python3.7 并解决ssl问题"></a>安装Python3.7 并解决ssl问题</h2><h3 id="安装Python"><a href="#安装Python" class="headerlink" title="安装Python"></a>安装Python</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> -y zlib zlib-dev openssl-devel sqlite-devel bzip2-devel libffi libffi-devel gcc gcc-c++<span class="token function">wget</span> http://www.openssl.org/source/openssl-1.1.1.tar.gz<span class="token function">tar</span> -zxvf openssl-1.1.1.tar.gz<span class="token builtin class-name">cd</span> openssl-1.1.1./config --prefix<span class="token operator">=</span><span class="token environment constant">$HOME</span>/openssl shared zlib<span class="token function">make</span> <span class="token operator">&&</span> <span class="token function">make</span> <span class="token function">install</span><span class="token builtin class-name">echo</span> <span class="token string">"export LD_LIBRARY_PATH=<span class="token variable">$LD_LIBRARY_PATH</span>:<span class="token environment constant">$HOME</span>/openssl/lib"</span> <span class="token operator">>></span> <span class="token environment constant">$HOME</span>/.bash_profile<span class="token builtin class-name">source</span> <span class="token environment constant">$HOME</span>/.bash_profileyum <span class="token function">install</span> zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc <span class="token function">make</span> libffi-devel -yyum <span class="token function">install</span> python-pip -y<span class="token function">wget</span> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz<span class="token function">tar</span> -zxvf Python-3.7.0.tgz./configure <span class="token assign-left variable">prefix</span><span class="token operator">=</span>/usr/local/python3 --with-openssl<span class="token operator">=</span><span class="token environment constant">$HOME</span>/openssl<span class="token function">make</span> <span class="token operator">&&</span> <span class="token function">make</span> <span class="token function">install</span><span class="token function">ln</span> -s /usr/local/python3/bin/python3.7 /usr/bin/python3.7 <span class="token function">ln</span> -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3.7<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="1-安装openssl"><a href="#1-安装openssl" class="headerlink" title="1.安装openssl"></a>1.安装openssl</h3><p>首先要安装openssl,因为python3需要引用openssl模块,但是centos需要的openssl版本最低为1.0.2,但是centos 默认的为1.0.1,所以需要重新更新openssl</p><hr><h3 id="2-测试https是否可用"><a href="#2-测试https是否可用" class="headerlink" title="2.测试https是否可用"></a>2.测试https是否可用</h3><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> urllib<span class="token punctuation">.</span>requesturl <span class="token operator">=</span> <span class="token string">'https://www.baidu.com'</span>b <span class="token operator">=</span> urllib<span class="token punctuation">.</span>request<span class="token punctuation">.</span>urlopen<span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token keyword">print</span> <span class="token punctuation">(</span>b<span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>报错</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">urllib.error.URLError: <span class="token operator"><</span>urlopen error <span class="token punctuation">[</span>SSL: CERTIFICATE_VERIFY_FAILED<span class="token punctuation">]</span> certificate verify failed <span class="token punctuation">(</span>_ssl.c:833<span class="token punctuation">)</span><span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h5 id="解决方法"><a href="#解决方法" class="headerlink" title="解决方法"></a>解决方法</h5><p>全局取消证书验证</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">import</span> sslssl._create_default_https_context <span class="token operator">=</span> ssl._create_unverified_context<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><h3 id="3-安装依赖"><a href="#3-安装依赖" class="headerlink" title="3.安装依赖"></a>3.安装依赖</h3><p>安装requirements.txt依赖:pip install -r requirements.txt</p><p>问题:cenos自带python2,如电脑上同时装了python2(2.7)和python3(3.7),当使用pip安装时默认应安装到python2中,pip3安装时应安装到python3中,但奇怪的是使用pip安装时每次都定位到python3中,不知是啥原因,也不知如何将其重定向到python2中,索性手动指定pip到python2中<br>查看pip版本</p><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">pip -V pip <span class="token number">18.0</span> from /usr/local/lib/python3.5/dist-packages/pip <span class="token punctuation">(</span>python <span class="token number">3.5</span><span class="token punctuation">)</span>pip2 -V pip <span class="token number">8.1</span>.1 from /usr/lib/python2.7/dist-packages <span class="token punctuation">(</span>python <span class="token number">2.7</span><span class="token punctuation">)</span>pip3 -V pip <span class="token number">18.0</span> from /usr/local/lib/python3.5/dist-packages/pip <span class="token punctuation">(</span>python <span class="token number">3.5</span><span class="token punctuation">)</span>解决方法pip指定python版本安装安装到python2.7版本中:sudo pip2 <span class="token function">install</span> 模块名 或 python2 -m pip <span class="token function">install</span> 模块名安装到python3.5版本中:sudo pip3 <span class="token function">install</span> 模块名 或 python3.5 -m pip <span class="token function">install</span> 模块名<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="4-linux-中后台运行python脚本"><a href="#4-linux-中后台运行python脚本" class="headerlink" title="4.linux 中后台运行python脚本"></a>4.linux 中后台运行python脚本</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">nohup</span> python yourscript.py <span class="token operator">&</span>可以让你的程序在后台运行,控制台输出导向nohup.out文件使用nobup命令 结尾处加一个<span class="token operator">&</span> 符号<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h5 id="2、关闭命令"><a href="#2、关闭命令" class="headerlink" title="2、关闭命令"></a>2、关闭命令</h5><h6 id="1、查看进程"><a href="#1、查看进程" class="headerlink" title="1、查看进程"></a>1、查看进程</h6><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"> <span class="token comment"># ps -ef|grep python</span> 或者 <span class="token comment"># ps -ef|grep Job</span><span class="token number">2</span>、关闭进程 <span class="token comment"># kill -9 19913</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h5 id="3、检查"><a href="#3、检查" class="headerlink" title="3、检查"></a>3、检查</h5><p>用1中查看进程的命令,检查或确认进程是否真正被关闭。</p>]]></content>
<categories>
<category> Python </category>
</categories>
<tags>
<tag> Linux </tag>
<tag> Python </tag>
</tags>
</entry>
</search>