![](/img/trans.png)
[英]How to fetch the logical name of a NIC card given the ip address associated with it ?
[英]Printing IP address of Nic card to bash using script
目前,我正在使用Vim在Linux上进行学校作业,我必须编写一个脚本来显示当前登录的用户,时间和日期,并仅列出Nic卡的IP地址。 除了IP地址部分,我所有工作正常。 如果有人可以提供帮助,我将不胜感激。
编辑以包括我目前的代码。
#!/bin/bash
Time=$(date)
IP=$(ifconfig ens33)
echo "The following user is currently logged in $USER"
echo ""
echo "The current time is $Time"
echo ""
echo "The IP information is $IP"
您可以使用awk
(IPv4)过滤ifconfig
的结果:
$ ifconfig ens33 | awk '/inet addr/{print substr($2, 6)}'
结果:
10.10.xx.xx
inet addr:
代表IPv4地址。
inet6 addr:
代表IPv6地址。
这条线
IP=$(ifconfig ens33| grep inet | sed 's/ */ /' | cut -d" " -f3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.