<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Shell: Obter o IP da interface de rede</title>
	<atom:link href="http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/feed/" rel="self" type="application/rss+xml" />
	<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/</link>
	<description>Programadores, uni-vos!</description>
	<lastBuildDate>Wed, 16 May 2012 12:39:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Tiago Oliveira de Jesus</title>
		<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/#comment-500</link>
		<dc:creator>Tiago Oliveira de Jesus</dc:creator>
		<pubDate>Fri, 01 May 2009 15:34:23 +0000</pubDate>
		<guid isPermaLink="false">http://codare.net/?p=314#comment-500</guid>
		<description>Dá até para remover 1 grep se usar o -n do sed:

ifconfig eth0 &#124; sed -n &#039;s/.*inet addr://g ; s&#124;\([0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\)\(.*\)&#124;\1&#124;gp&#039;</description>
		<content:encoded><![CDATA[<p>Dá até para remover 1 grep se usar o -n do sed:</p>
<p>ifconfig eth0 | sed -n &#8216;s/.*inet addr://g ; s|\([0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\)\(.*\)|\1|gp&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tiago Oliveira de Jesus</title>
		<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/#comment-499</link>
		<dc:creator>Tiago Oliveira de Jesus</dc:creator>
		<pubDate>Fri, 01 May 2009 15:26:37 +0000</pubDate>
		<guid isPermaLink="false">http://codare.net/?p=314#comment-499</guid>
		<description>Eca.. ficou feio aqui, acho que nem o lugar, sorry..

Da próxima posto noutro lugar.</description>
		<content:encoded><![CDATA[<p>Eca.. ficou feio aqui, acho que nem o lugar, sorry..</p>
<p>Da próxima posto noutro lugar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tiago Oliveira de Jesus</title>
		<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/#comment-498</link>
		<dc:creator>Tiago Oliveira de Jesus</dc:creator>
		<pubDate>Fri, 01 May 2009 15:25:12 +0000</pubDate>
		<guid isPermaLink="false">http://codare.net/?p=314#comment-498</guid>
		<description>Ual, precisei disso no mesmo dia, acabei fazendo assim:

#!/bin/bash
#
# Tiago Oliveira de Jesus - tiago@vgt.com.br
# /usr/local/bin/ip_gw.sh - 2009-04-29
#
# Script para pegar ip e gw da placa de rede dinamicamente.
#
# O script recebe como parametros a placa (ethX) + IP ou GW ou NET
# para retornar IP ou GW ou NETWORK:-)
#
# Exemplos:
# /usr/local/bin/ip_gw.sh eth1 IP
# 123.456.789.12
#
# /usr/local/bin/ip_gw.sh eth1 GW
# 123.456.789.1
#
# /usr/local/bin/ip_gw.sh eth1 NET
# 123.456.789.0/24
#

## CHANGELOG ##
# 2009-05-01 - Adicionada a variável de ambiente LANG para padronização das respostas
# 	       Retirado do post http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/
# 	       by Fabiano Pires
# 2009-05-01 - Adicionada if  para verificar se a placa existe
#
##############

LANG=C
PLACA=${1}
TIPO=${2}

PegaIP(){
	IP=$(ifconfig $PLACA &#124; grep &#039;inet addr:&#039;&#124;sed &#039;s/.*inet addr://g ; s&#124;\([0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\)\(.*\)&#124;\1&#124;g&#039;)
	echo $IP
}

PegaGW(){
	GW=$(ip route &#124;grep $PLACA&#124;grep default&#124;cut -d&quot; &quot; -f3)
	echo $GW
}

PegaNET(){
	NET=$(ip ro&#124;grep &quot;^\([0-9]\)&quot;&#124;grep &quot;/&quot;&#124;grep $PLACA&#124;cut -d&quot; &quot; -f1)
	echo $NET
}


if grep -qws $PLACA &lt;(ifconfig &#124;grep &#039;^eth&#039;&#124;cut -f1 -d&quot; &quot;)
then

	case $TIPO in
		IP)
			PegaIP
		;;
		GW)
			PegaGW
		;;
		NET)
			PegaNET
		;;
		*)
			echo &quot;Use $0 ethX {IP&#124;GW&#124;NET}&quot;
			exit
		;;
	esac
else
	echo &quot;$PLACA não existe&quot;
fi</description>
		<content:encoded><![CDATA[<p>Ual, precisei disso no mesmo dia, acabei fazendo assim:</p>
<p>#!/bin/bash<br />
#<br />
# Tiago Oliveira de Jesus &#8211; <a href="mailto:tiago@vgt.com.br">tiago@vgt.com.br</a><br />
# /usr/local/bin/ip_gw.sh &#8211; 2009-04-29<br />
#<br />
# Script para pegar ip e gw da placa de rede dinamicamente.<br />
#<br />
# O script recebe como parametros a placa (ethX) + IP ou GW ou NET<br />
# para retornar IP ou GW ou NETWORK:-)<br />
#<br />
# Exemplos:<br />
# /usr/local/bin/ip_gw.sh eth1 IP<br />
# 123.456.789.12<br />
#<br />
# /usr/local/bin/ip_gw.sh eth1 GW<br />
# 123.456.789.1<br />
#<br />
# /usr/local/bin/ip_gw.sh eth1 NET<br />
# 123.456.789.0/24<br />
#</p>
<p>## CHANGELOG ##<br />
# 2009-05-01 &#8211; Adicionada a variável de ambiente LANG para padronização das respostas<br />
# 	       Retirado do post <a href="http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/" rel="nofollow">http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/</a><br />
# 	       by Fabiano Pires<br />
# 2009-05-01 &#8211; Adicionada if  para verificar se a placa existe<br />
#<br />
##############</p>
<p>LANG=C<br />
PLACA=${1}<br />
TIPO=${2}</p>
<p>PegaIP(){<br />
	IP=$(ifconfig $PLACA | grep &#8216;inet addr:&#8217;|sed &#8216;s/.*inet addr://g ; s|\([0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\.[0-9]\{,3\}\)\(.*\)|\1|g&#8217;)<br />
	echo $IP<br />
}</p>
<p>PegaGW(){<br />
	GW=$(ip route |grep $PLACA|grep default|cut -d&#8221; &#8221; -f3)<br />
	echo $GW<br />
}</p>
<p>PegaNET(){<br />
	NET=$(ip ro|grep &#8220;^\([0-9]\)&#8221;|grep &#8220;/&#8221;|grep $PLACA|cut -d&#8221; &#8221; -f1)<br />
	echo $NET<br />
}</p>
<p>if grep -qws $PLACA &lt;(ifconfig |grep &#8216;^eth&#8217;|cut -f1 -d&#8221; &#8220;)<br />
then</p>
<p>	case $TIPO in<br />
		IP)<br />
			PegaIP<br />
		;;<br />
		GW)<br />
			PegaGW<br />
		;;<br />
		NET)<br />
			PegaNET<br />
		;;<br />
		*)<br />
			echo &#8220;Use $0 ethX {IP|GW|NET}&#8221;<br />
			exit<br />
		;;<br />
	esac<br />
else<br />
	echo &#8220;$PLACA não existe&#8221;<br />
fi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jorge Pereira</title>
		<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/#comment-497</link>
		<dc:creator>Jorge Pereira</dc:creator>
		<pubDate>Thu, 30 Apr 2009 17:46:06 +0000</pubDate>
		<guid isPermaLink="false">http://codare.net/?p=314#comment-497</guid>
		<description>Caso prefira fazer com sed, seria algo como!

[leapstone@node0 ~]$ LANG=C;/sbin/ifconfig eth0 &#124; sed &#039;/inet addr/!d; s/.*addr://; s/ .*//g&#039;
172.27.3.9
[leapstone@node0 ~]$

[]s</description>
		<content:encoded><![CDATA[<p>Caso prefira fazer com sed, seria algo como!</p>
<p>[leapstone@node0 ~]$ LANG=C;/sbin/ifconfig eth0 | sed &#8216;/inet addr/!d; s/.*addr://; s/ .*//g&#8217;<br />
172.27.3.9<br />
[leapstone@node0 ~]$</p>
<p>[]s</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thiago Santos</title>
		<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/#comment-496</link>
		<dc:creator>Thiago Santos</dc:creator>
		<pubDate>Wed, 29 Apr 2009 19:55:23 +0000</pubDate>
		<guid isPermaLink="false">http://codare.net/?p=314#comment-496</guid>
		<description>Nop, viagem minha, vi o &quot;;&quot; e confundi.</description>
		<content:encoded><![CDATA[<p>Nop, viagem minha, vi o &#8220;;&#8221; e confundi.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thiago Santos</title>
		<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/#comment-495</link>
		<dc:creator>Thiago Santos</dc:creator>
		<pubDate>Wed, 29 Apr 2009 19:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://codare.net/?p=314#comment-495</guid>
		<description>&quot;print&quot; seria mais um processo.</description>
		<content:encoded><![CDATA[<p>&#8220;print&#8221; seria mais um processo.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eugenidodonov</title>
		<link>http://codare.net/2009/04/29/shell-obter-o-ip-da-interface-de-rede/#comment-494</link>
		<dc:creator>eugenidodonov</dc:creator>
		<pubDate>Wed, 29 Apr 2009 14:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://codare.net/?p=314#comment-494</guid>
		<description>...ou usando awk:
LANG=C ifconfig eth0 &#124; awk &#039;/inet addr/ {sub(/:/,&quot; &quot;); print $3}&#039;

A diferença é que neste caso somente 1 processo será executado depois do ifconfig (awk), e não 3 (grep, cut, cut) :)</description>
		<content:encoded><![CDATA[<p>&#8230;ou usando awk:<br />
LANG=C ifconfig eth0 | awk &#8216;/inet addr/ {sub(/:/,&#8221; &#8220;); print $3}&#8217;</p>
<p>A diferença é que neste caso somente 1 processo será executado depois do ifconfig (awk), e não 3 (grep, cut, cut) :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

