找到BASH内部IP地址 [英] Find internal IP address with BASH

查看:120
本文介绍了找到BASH内部IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道让你的内部IP的许多方面(的ifconfig,IP地址,/ etc / hosts文件等),但我试图写一个bash脚本,将始终返回内部IP。问题是,许多单行(/ sbin目录/使用ifconfig | grep的INET |头-1 | SED的/ \\:/ /'| awk的'{打印$ 3}')可以返回多个IP地址,我需要区分手动内部之一。

I am already aware of many ways of getting your internal IP (ifconfig, ip addr, /etc/hosts, etc), but I am trying to write a bash script that will always return the internal IP. The problem is, many one-liners (/sbin/ifconfig|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}') can return multiple IPs, and I need to distinguish the internal one manually.

我怀疑到计算机,不存在之间和一个外部IP和一个内部IP,因此没有100%,保证的方式来获得正确的IP差。

I suspect that to the computer, there is no difference between and an external IP and an internal IP, and thus no 100%, guaranteed way to get the right IP.

最终的结果是,该脚本将返回内部IP,不管它的一个192地址或204地址等

The end result is that this script will return the internal IP, no matter if its a 192 address or a 204 address, etc.

先谢谢了。

推荐答案

主机名-i 应该希望给你同样的结果。

"hostname -i" should hopefully give you the same result

这篇关于找到BASH内部IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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