<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>https://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>https://jackxiang.com/post//</link>
<title><![CDATA[ shell检查输入的字符串是不是ip ]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Sun, 12 Jun 2016 08:16:17 +0000</pubDate> 
<guid>https://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	每天早上2-3小时shell论坛,今天终于把精华帖子恳完了,放点好脚本给各位,学shell上cu,没事逛逛论坛,心情好的时候看看精华贴.进步那真是飞一般的感觉.<br/>不过新手最好还是先潜水一个月,在开始发帖回帖.最近论坛帖子质量严重下降都是1+1=?.<br/>zj@zj:~/Script/cushell/08.11.04$ cat checkip.sh <br/><textarea name="code" class="php" rows="15" cols="100">
#!/bin/bash


printerr () &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;incorrect IP format.&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;readip
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chkip
&#125;

readip () &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read -p &quot;Your IP: &quot; IP
&#125;

chkip () &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;$IP&quot; &#124; grep -Eq &#039;[^0-9.]&#124;^&#92;.&#124;&#92;.$&#124;^0*&#92;.&#124;&#92;.&#92;.&#039; &amp;&amp; printerr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ $(echo -e &quot;$&#123;IP//./&#92;n&#125;&quot; &#124; wc -l) -ne 4 ] &amp;&amp; printerr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i in $&#123;IP//./ &#125; ; do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $i &#124; grep -Eq &quot;^0+[^0]&quot; &amp;&amp; printerr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ $((10#$i/8)) -gt 31 ] &amp;&amp; printerr

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;done
&#125;

if [ &quot;$1&quot; ]; then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IP=$1
else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;readip
fi
chkip
echo &quot;$IP is good!&quot;
</textarea><br/>解释下:<br/>grep -Eq &#039;[^0-9.]&#124;^&#92;.&#124;&#92;.$&#124;^0*&#92;.&#124;&#92;.&#92;.&#039;<br/>[^0-9.]是不是有除了0-9与.之外的字符<br/>^&#92;.&#124;&#92;.$&nbsp;&nbsp;以.开头 or 以.结尾<br/>^0*&#92;.&#124;&#92;.&#92;. 以0开头 or 连续两个.<br/>以上三种情况都是错误的哦,所以就printerr<br/><br/>echo -e &quot;$&#123;IP//./&#92;n&#125;&quot; &#124; wc -l说实话前面那种替换我也是first time.就是讲.替换为换行,3个点就是4行了哦.不是3个点也就printerr<br/><br/>$((10#$i/8)) -gt 31 这个就是判断是不是&lt;=255的了,当然你也可以自己修改成$i -gt 255<br/><br/>OK解释完毕^_^<br/>zj@zj:~/Script/cushell/08.11.04$ ./checkip.sh 1.2.3.4<br/>1.2.3.4 is <br/>zj@zj:~/Script/cushell/08.11.04$ ./checkip.sh 01.2.3.4<br/>incorrect IP format.<br/>Your IP: a.b.a.d<br/>incorrect IP format.<br/>Your IP: 266.1.1.1<br/>incorrect IP format.<br/>Your IP: 244.255.255.255<br/>244.255.255.255 is<br/><br/>来自：http://blog.chinaunix.net/uid-9950859-id-98351.html<br/>更复杂的且更精确的判断：http://www.shangxueba.com/jingyan/1898546.html
]]>
</description>
</item><item>
<link>https://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论]  shell检查输入的字符串是不是ip ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>