[英]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.