哪个终端命令仅获取IP地址,而没有其他内容? [英] Which terminal command to get just IP address and nothing else?

查看:55
本文介绍了哪个终端命令仅获取IP地址,而没有其他内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅将IP地址(inet)用作我编写的脚本中的参数.

I'm trying to use just the IP address (inet) as a parameter in a script I wrote.

在UNIX终端中是否有一种简单的方法来获取IP地址,而不是通过ifconfig进行查找?

Is there an easy way in a unix terminal to get just the IP address, rather than looking through ifconfig?

推荐答案

您可以编写仅返回IP的脚本,例如:

You can write a script that only return the IP like:

/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'

对于MAC:

ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\  -f2

或者对于linux系统

Or for linux system

hostname -i | awk '{print $3}' # Ubuntu 

hostname -i # Debian

这篇关于哪个终端命令仅获取IP地址,而没有其他内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆