<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>刀刀 &#124; Python,Nginx,Linux,FreeBSD</title>
	<atom:link href="http://tech.foolpig.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.foolpig.com</link>
	<description></description>
	<pubDate>Sat, 31 Mar 2012 09:25:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>mysql 忘记密码</title>
		<link>http://tech.foolpig.com/2012/03/31/mysql-passwd/</link>
		<comments>http://tech.foolpig.com/2012/03/31/mysql-passwd/#comments</comments>
		<pubDate>Sat, 31 Mar 2012 09:25:11 +0000</pubDate>
		<dc:creator>foolpig</dc:creator>
		
		<category><![CDATA[东写西读]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[忘记密码]]></category>

		<guid isPermaLink="false">http://tech.foolpig.com/?p=371</guid>
		<description><![CDATA[如果 MySQL 正在运行，
首先杀之: killall -TERM mysqld(如果是windows,直接调出进程管理器,结束之)
以安全模式启动 MySQL:
/usr/bin/mysqld_safe &#8211;skip-grant-tables &#038;
(windows 下 mysql安装所以盘/mysql/bin/safe_mys... ]]></description>
			<content:encoded><![CDATA[<p>如果 MySQL 正在运行，<br />
首先杀之: killall -TERM mysqld(如果是windows,直接调出进程管理器,结束之)<br />
以安全模式启动 MySQL:<br />
/usr/bin/mysqld_safe &#8211;skip-grant-tables &#038;<br />
(windows 下 mysql安装所以盘/mysql/bin/safe_mysqld &#8211;skip-grant-tables )<br />
就可以不需要密码就进入 MySQL 了.<br />
然后就是<br />
>use mysql<br />
>update user set password=password(&#8221;new_pass&#8221;) where user=&#8221;root&#8221;;<br />
>flush privileges; </p>
<p>重新杀 MySQL,用正常方法启动 MySQL. </p>
]]></content:encoded>
			<wfw:commentRss>http://tech.foolpig.com/2012/03/31/mysql-passwd/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ip子网掩码的快速计算</title>
		<link>http://tech.foolpig.com/2012/03/31/ip-netmask/</link>
		<comments>http://tech.foolpig.com/2012/03/31/ip-netmask/#comments</comments>
		<pubDate>Sat, 31 Mar 2012 07:18:43 +0000</pubDate>
		<dc:creator>foolpig</dc:creator>
		
		<category><![CDATA[东写西读]]></category>

		<category><![CDATA[ip]]></category>

		<category><![CDATA[子网快速计算]]></category>

		<guid isPermaLink="false">http://tech.foolpig.com/?p=368</guid>
		<description><![CDATA[我们都知道IP子网的计算规则为：
1、IP与掩码进行位与计算得到初值，
2、然后将掩码进行取反，再与IP进行或运算得到终值。
ip子网掩码的快速计算防范有如下2种：
1、掩码的表示方法类似为2... ]]></description>
			<content:encoded><![CDATA[<p><strong>我们都知道IP子网的计算规则为：</strong><br />
1、IP与掩码进行位与计算得到初值，</p>
<p>2、然后将掩码进行取反，再与IP进行或运算得到终值。</p>
<p><strong>ip子网掩码的快速计算防范有如下2种：</strong><br />
1、掩码的表示方法类似为255.255.0.0</p>
<p>计算方法：将掩码的相对位置用255相减得到差值，将这个差值加到IP的相应位置，超过255往前进位</p>
<p>比如：IP：1.188.0.0 掩码：255.252.0.0</p>
<p>将掩码的相对位置用255相减分别得到：0 3 255 255</p>
<p>然后加到IP的相对位置得到：1 191 255 255</p>
<p>所以相应的IP范围为：1.188.0.0 - 1.191.255.255</p>
<p>当然子网可用IP地址为子网地址+1 至 广播地址-1，即为：1.188.0.1 - 1.191.255.254</p>
<p> </p>
<p>2、子网掩码表示方法为/16</p>
<p>计算方法：将掩码用32相减，得到的值从右往左拆分成多个8的和，然后将此多个值分别表示成2的幂-1，得到的值从右往左加到IP上即可</p>
<p>例如：42.48.0.0/15</p>
<p>将掩码用32相减得到17，拆分为多个8的值为：1+8+8，表示成2的幂并减去1，为1 255 255，从右往左加到相应的IP位置为： 42 49 255 255</p>
<p>那么IP地址范围：42.48.0.0 - 42.49.255.255</p>
<p>有效子网地址：42.48.0.1 - 42.49.255.254</p>
<p> <br />
附1：子网掩码计算的python脚本</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">import sys
import ctypes
&nbsp;
ip = sys.argv<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #c20cb9; font-weight: bold;">nm</span> = sys.argv<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
def nd<span style="color: #7a0874; font-weight: bold;">&#40;</span>ip,<span style="color: #c20cb9; font-weight: bold;">nm</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
    ip1 = ip.split<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    nm1 = nm.split<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    a = <span style="color: #7a0874; font-weight: bold;">&#91;</span> str<span style="color: #7a0874; font-weight: bold;">&#40;</span>int<span style="color: #7a0874; font-weight: bold;">&#40;</span>i<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span> int<span style="color: #7a0874; font-weight: bold;">&#40;</span>m<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> i,m <span style="color: #000000; font-weight: bold;">in</span> map<span style="color: #7a0874; font-weight: bold;">&#40;</span>None,ip1,nm1<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    b = <span style="color: #7a0874; font-weight: bold;">&#91;</span> str<span style="color: #7a0874; font-weight: bold;">&#40;</span>int<span style="color: #7a0874; font-weight: bold;">&#40;</span>i<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> ctypes.c_ubyte<span style="color: #7a0874; font-weight: bold;">&#40;</span>~int<span style="color: #7a0874; font-weight: bold;">&#40;</span>m<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.value<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> i,m <span style="color: #000000; font-weight: bold;">in</span> map<span style="color: #7a0874; font-weight: bold;">&#40;</span>None,ip1,nm1<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> a,b
print <span style="color: #ff0000;">'.'</span>.join<span style="color: #7a0874; font-weight: bold;">&#40;</span>nd<span style="color: #7a0874; font-weight: bold;">&#40;</span>ip,<span style="color: #c20cb9; font-weight: bold;">nm</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> + <span style="color: #ff0000;">&quot;-&quot;</span> + <span style="color: #ff0000;">'.'</span>.join<span style="color: #7a0874; font-weight: bold;">&#40;</span>nd<span style="color: #7a0874; font-weight: bold;">&#40;</span>ip,<span style="color: #c20cb9; font-weight: bold;">nm</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>将上面的代码保存为 ip.py文件，然后执行</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># python ip.py &lt;ip地址&gt; &lt;netmask&gt;</span>
python ip.py 27.98.224.0 255.255.224.0</pre></div></div>

<p>附2:计算工具：<a href="http://tech.foolpig.com/wp-content/uploads/2012/03/masktool.rar">masktool</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.foolpig.com/2012/03/31/ip-netmask/feed/</wfw:commentRss>
		</item>
		<item>
		<title>shell脚本自动输入y yes 实现简单的交互</title>
		<link>http://tech.foolpig.com/2012/03/30/shell/</link>
		<comments>http://tech.foolpig.com/2012/03/30/shell/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 05:55:38 +0000</pubDate>
		<dc:creator>foolpig</dc:creator>
		
		<category><![CDATA[东写西读]]></category>

		<category><![CDATA[shell]]></category>

		<category><![CDATA[交互]]></category>

		<guid isPermaLink="false">http://tech.foolpig.com/?p=367</guid>
		<description><![CDATA[




例如
执行脚本时循环出现 [y/N]:  让你选择，怎样写一个脚本使其自动选择y。 

非常简单：yes &#124; ./你的脚本
注意不是 y &#124; ./你的脚本
或者echo y &#124; ./你的脚本




... ]]></description>
			<content:encoded><![CDATA[<table style="width: 100%; table-layout: fixed;" border="0">
<tbody>
<tr>
<td>
<div id="blog_text" class="cnt">
<p>例如</p>
<p><span>执行脚本时循环出现 [y/N]:  让你选择，怎样写一个脚本使其自动选择y。 </span></p>
<div style="text-align: left;"></div>
<div style="text-align: left;">非常简单：yes | ./你的脚本</div>
<div style="text-align: left;">注意不是 y | ./你的脚本</div>
<div style="text-align: left;">或者echo y | ./你的脚本</div>
</div>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://tech.foolpig.com/2012/03/30/shell/feed/</wfw:commentRss>
		</item>
		<item>
		<title>traceroute和tracert的区别</title>
		<link>http://tech.foolpig.com/2011/12/12/tracert_traceroute/</link>
		<comments>http://tech.foolpig.com/2011/12/12/tracert_traceroute/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 09:22:34 +0000</pubDate>
		<dc:creator>foolpig</dc:creator>
		
		<category><![CDATA[东写西读]]></category>

		<category><![CDATA[tracepath]]></category>

		<category><![CDATA[traceroute]]></category>

		<category><![CDATA[tracert]]></category>

		<guid isPermaLink="false">http://tech.foolpig.com/?p=366</guid>
		<description><![CDATA[windows下的tracert和linux/BSD/router下的traceroute都用于探测数据包从源到目的经过路由的IP，但两者探测的方法却有差别。
默认情况下，tracert是向目的地址发出ICMP请求回显数据包，而traceroute是向目... ]]></description>
			<content:encoded><![CDATA[<p>windows下的tracert和linux/BSD/router下的traceroute都用于探测数据包从源到目的经过路由的IP，但两者探测的方法却有差别。<br />
默认情况下，tracert是向目的地址发出ICMP请求回显数据包，而traceroute是向目的地址的某个端口（大于30000）发送UDP数据报。<br />
两者用于探测的数据类型不同。但他们也有一个共同点：都是通过设置发送包的TTL的值从1开始、逐次增1的方法来探测。</p>
<p>也就是说tracert是ICMP，而traceroute是UDP的</p>
<p>linux 的 traceroute 可加 -I 参数改用 ICMP</p>
<p>PS：tracepath与traceroute差别不大，但是tracepath不能用-n来取消DNS query</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.foolpig.com/2011/12/12/tracert_traceroute/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[转]Linux下实现自动设置SSH代理</title>
		<link>http://tech.foolpig.com/2011/11/15/%e8%bd%aclinux%e4%b8%8b%e5%ae%9e%e7%8e%b0%e8%87%aa%e5%8a%a8%e8%ae%be%e7%bd%aessh%e4%bb%a3%e7%90%86/</link>
		<comments>http://tech.foolpig.com/2011/11/15/%e8%bd%aclinux%e4%b8%8b%e5%ae%9e%e7%8e%b0%e8%87%aa%e5%8a%a8%e8%ae%be%e7%bd%aessh%e4%bb%a3%e7%90%86/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 02:16:25 +0000</pubDate>
		<dc:creator>foolpig</dc:creator>
		
		<category><![CDATA[东写西读]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[proxy]]></category>

		<category><![CDATA[ssh]]></category>

		<category><![CDATA[代理]]></category>

		<guid isPermaLink="false">http://tech.foolpig.com/?p=365</guid>
		<description><![CDATA[SSH的巨大价值体现在能够配置为代理服务器上。不像在Windows下每次还需要手动登录设置，Linux有很好的工具链能够实现自动设置SSH 代理，就是expect和ssh的联合使用，再加上proxychains，任何程序... ]]></description>
			<content:encoded><![CDATA[<p>SSH的巨大价值体现在能够配置为代理服务器上。不像在Windows下每次还需要手动登录设置，Linux有很好的工具链能够实现自动设置SSH 代理，就是expect和ssh的联合使用，再加上proxychains，任何程序都可以享用代理了，在此我简单介绍一下。</p>
<p>首先要安装expect和openssh，如果没有，Ubuntu下输入apt-get install expect openssh-client即可安装。接下来需要写一段脚本：</p>
<div class="wp_codebox_msgheader"><span class="right"><sup><a title="WP-CodeBox HowTo?" href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank"><span style="color: #99cc00;"><br />
</span></a></sup></span></div>
<div class="wp_codebox">
<table border="0">
<tbody>
<tr id="p19331">
<td id="p1933code1" class="code">
<pre class="bash" style="font-family: monospace;"><span style="font-style: italic; color: #666666;">#!/usr/bin/expect</span>
 <span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #000000;">60</span>
spawn <span style="color: #000000; font-weight: bold;">/</span> usr<span style="color: #000000; font-weight: bold;">/</span> bin<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-D</span> 本地端口 <span style="color: #660033;">-g</span> 用户名<span style="color: #000000; font-weight: bold;">@</span> 服务器
expect <span style="color: #7a0874; font-weight: bold;">{</span>
 <span style="color: #ff0000;">"password:"</span> <span style="color: #7a0874; font-weight: bold;">{</span>
send <span style="color: #ff0000;">"密码<span style="color: #000099; font-weight: bold;">/r</span> "</span>
 <span style="color: #7a0874; font-weight: bold;">}</span>
 <span style="color: #7a0874; font-weight: bold;">}</span>
interact <span style="color: #7a0874; font-weight: bold;">{</span>
timeout <span style="color: #000000;">60</span> <span style="color: #7a0874; font-weight: bold;">{</span> send <span style="color: #ff0000;">" "</span> <span style="color: #7a0874; font-weight: bold;">}</span>
 <span style="color: #7a0874; font-weight: bold;">}</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>把上面的中文替换成对应内容，保存为一个脚本文件，例如sshproxy.sh，然后给它执行权限，chmod +x sshproxy.sh。在终端下运行./sshproxy.sh，就会发现自动登录到了服务器上，而且在本地建立了一个socks5代理。而且使用这段脚本还不用担心会被踢，因为每60秒都要发送一个空格表示还在活动。如果把sshproxy.sh放到自动启动，那么以后每次启动都可以自动建立代理了。</p>
<p>这种方法建立的代理是socks5代理，在浏览器中很容易配置使用，但如果其他程序也想用它，而没有代理功能，该怎么办呢？在Windows下面的确不好办（需要各种付费的、不稳定的代理转换工具），而在Linux下一切很简单，只需要一个名叫proxychains的工具。Ubuntu安装方法为 apt-get install proxychains。安装完以后要设置/etc/proxychains.conf文件，删除[ProxyList]后面的内容，然后添加</p>
<div class="wp_codebox_msgheader"><span class="right"><sup><a title="WP-CodeBox HowTo?" href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank"><span style="color: #99cc00;"><br />
</span></a></sup></span></div>
<div class="wp_codebox">
<table border="0">
<tbody>
<tr id="p19332">
<td id="p1933code2" class="code">
<pre class="bash" style="font-family: monospace;">socks5 127.0.0.1 端口</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>把“端口”替换为SSH代理设置的端口。然后在想要运行的程序前加上proxychains ，即可使用代理。例如输入proxychains wget http://www.youtube.com -r，即可给wget设置SSH代理去下载。</p>
<p>正如其名，实际上proxychains是个代理链，我们可以设置多个代理，实现多级跳板连接。用在SSH代理上实在是大才小用了。</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.foolpig.com/2011/11/15/%e8%bd%aclinux%e4%b8%8b%e5%ae%9e%e7%8e%b0%e8%87%aa%e5%8a%a8%e8%ae%be%e7%bd%aessh%e4%bb%a3%e7%90%86/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

