Linux的bash脚本来提取IP地址 [英] Linux bash script to extract IP address
问题描述
我想就我的Debian 7.3大脚本(有点像翻译以及更多新的用户友好的环境)。我有个问题。我只想使用一些命令给我的信息的。例如我的ifconfig如下:
I want to make big script on my Debian 7.3 ( something like translated and much more new user friendly enviroment ). I have a problem. I want to use only some of the informations that commands give me. For example my ifconfig looks like:
eth0 Link encap:Ethernet HWaddr 08:00:27:a3:e3:b0
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea3:e3b0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1904 errors:0 dropped:0 overruns:0 frame:0
TX packets:2002 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1309425 (1.2 MiB) T
我想只显示在线的IP地址:回声您的IP地址为:(IP地址)。是否有任何的命令,让我做这样的事情,在流来搜索信息我想?我知道的grep
和 SED
但我不跟他们真的很好。
I want to display only the IP address in line: echo "Your IP address is: (IP_ADDRESS )". Is there any command that allow me to do such a thing, to search in stream for informations I want to get?. I know about grep
and sed
but I am not really good with them.
编辑:首先说,感谢你帮我解决这个问题,现在我知道更多。其次要说的项目正在进行中。如果有人有兴趣只是下午我。
Firstly to say thank you for helping me with this problem, now I know much more. Secondly to say project is in progress. If anyone would be interested in it just pm me.
推荐答案
要刚刚获得你的IP地址:
To just get your IP address:
echo `ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
这会给你的eth0的IP地址。
This will give you the IP address of eth0.
这篇关于Linux的bash脚本来提取IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!