您现在的位置是:网站首页> 编程资料编程资料
Shell脚本中获取本机ip地址的3个方法_linux shell_
2023-05-26
404人已围观
简介 Shell脚本中获取本机ip地址的3个方法_linux shell_
方法一:
复制代码 代码如下:
/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
or
/sbin/ifconfig|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p'
方法二:
复制代码 代码如下:
local_host="`hostname --fqdn`"
local_ip=`host $local_host 2>/dev/null | awk '{print $NF}'`
方法三:
复制代码 代码如下:
local_host="`hostname --fqdn`"
nslookup -sil $local_host 2>/dev/null | grep Address: | sed '1d' | sed 's/Address://g'
您可能感兴趣的文章:
相关内容
- Shell脚本实现IP地址合法性判断_linux shell_
- Shell脚本8种字符串截取方法总结_linux shell_
- Shell字符串比较相等、不相等方法小结_linux shell_
- Shell中删除某些文件外所有文件的3个方法_linux shell_
- Shell脚本IF条件判断和判断条件总结_linux shell_
- Shell脚本中判断输入变量或者参数是否为空的方法_linux shell_
- Shell脚本中判断输入参数个数的方法_linux shell_
- Shell最多支持多少个参数?_linux shell_
- Python执行Linux系统命令的4种方法_linux shell_
- bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory_linux shell_
