<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://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>http://jackxiang.com/post//</link>
<title><![CDATA[awk 获取 Linux下的ip地址]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Thu, 15 Sep 2011 07:54:32 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	法一：<br/><textarea name="code" class="html" rows="15" cols="100">
/sbin/ifconfig &#124; /bin/awk &#039;BEGIN&#123;RS=&quot;&quot;&#125; /eth[0-9][^:]/ &#123;print substr($7,6)&#125;&#039; &#124; tail -1
</textarea><br/>法二：<br/><textarea name="code" class="html" rows="15" cols="100">
ifconfig&nbsp;&nbsp;&#124;awk&nbsp;&nbsp;-F&#039;addr:&#124;&nbsp;&nbsp;Bcast&#039;&nbsp;&nbsp; &#039;/Bcast/&#123;print $2&#125;&#039; 
</textarea><br/><br/><br/>由于不同系统中ifconfig返回信息的格式有一定差别，故分开讨论：<br/><br/>Linux:<br/><textarea name="code" class="html" rows="15" cols="100">
LC_ALL=C ifconfig&nbsp;&nbsp;&#124; grep &#039;inet addr:&#039;&#124; grep -v &#039;127.0.0.1&#039; &#124;
cut -d: -f2 &#124; awk &#039;&#123; print $1&#125;&#039;
</textarea><br/>FreeBSD/OpenBSD:<br/><textarea name="code" class="html" rows="15" cols="100">
LC_ALL=C ifconfig&nbsp;&nbsp;&#124; grep -E &#039;inet.[0-9]&#039; &#124; grep -v &#039;127.0.0.1&#039; &#124;
awk &#039;&#123; print $2&#125;&#039;
</textarea><br/>Solaris:<br/><textarea name="code" class="html" rows="15" cols="100">
LC_ALL=C ifconfig -a &#124; grep inet &#124; grep -v &#039;127.0.0.1&#039; &#124;
awk &#039;&#123; print $2&#125;&#039;
</textarea><br/>三段代码的原理类似，都是先获取含有IP的行，再去掉含有127.0.0.1的行。最后获取IP所在的列 <br/><textarea name="code" class="html" rows="15" cols="100">
#!/bin/sh
# Shell script scripts to read ip address
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project &lt;http://cyberciti.biz/fb/&gt;
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Get OS name
OS=`uname`
IO=&quot;&quot; # store IP
case $OS in
&nbsp;&nbsp; Linux) IP=`ifconfig&nbsp;&nbsp;&#124; grep &#039;inet addr:&#039;&#124; grep -v &#039;127.0.0.1&#039; &#124; cut -d: -f2 &#124; awk &#039;&#123; print $1&#125;&#039;`;;
&nbsp;&nbsp; FreeBSD&#124;OpenBSD) IP=`ifconfig&nbsp;&nbsp;&#124; grep -E &#039;inet.[0-9]&#039; &#124; grep -v &#039;127.0.0.1&#039; &#124; awk &#039;&#123; print $2&#125;&#039;` ;;
&nbsp;&nbsp; SunOS) IP=`ifconfig -a &#124; grep inet &#124; grep -v &#039;127.0.0.1&#039; &#124; awk &#039;&#123; print $2&#125; &#039;` ;;
&nbsp;&nbsp; *) IP=&quot;Unknown&quot;;;
esac
echo &quot;$IP&quot;
</textarea><br/><br/>参考：http://linux-wiki.cn/wiki/Shell%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8DIP%E5%9C%B0%E5%9D%80
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] awk 获取 Linux下的ip地址]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>