azs
deepin
2017-11-27 05:27 lz 可以使用Python来写这个程序,而不是臃肿的shell脚本
Reply Like 0 View the author
https://bbs.deepin.org/post/149000
lz 可以使用Python来写这个程序,而不是臃肿的shell脚本
https://bbs.deepin.org/post/149000
如果用Python, 可以使用一些类库来减少你的工作,比如 netifaces ,psutil 可以用来获取网卡的信息。减少你 ...

address=$(ip addr show label $default_interface scope global | awk '$1 == "inet" { print $2,$4}')
#! /bin/sh
default_route=$(ip route show)
default_interface=$(echo $default_route | sed -e 's/^.*dev \([^ ]*\).*$/\1/' | head -n 1)
address=$(ip addr show label $default_interface scope global )
echo ${address} > inet.log
#上边这行就是显示你的网卡全部信息
#网络名称
#网卡接口
#ip 地 址
ip=$(echo $address | awk '{print $1 }')
ip=${ip%%/*}
#广播地址(这个不需要)
#broadcast=$(echo $address | awk '{print $2 }')
#子网掩码
mask=$(route -n |grep 'U[ \t]' | head -n 1 | awk '{print $3}')
#默认网关
gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}')
#dns
dns=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
#MAC地址
MAC=
#网卡速率
txqueuelen=
echo 网络名称:
echo 网卡接口:
echo ip 地 址: $ip
echo 子网掩码: $mask
#echo 广播地址: $broadcast
echo 默认网关: $gateway
echo 首选 DNS: $dns
echo MAC 地址: $mac
echo 网卡速率: $txqueuelen
https://bbs.deepin.org/post/149000
这行应该就是取网卡信息的命令。 你把 | awk '$1 == "inet" { print $2,$4}' 这段删除了就能显示所有的网卡 ...
https://bbs.deepin.org/post/149000
这行应该就是取网卡信息的命令。 你把 | awk '$1 == "inet" { print $2,$4}' 这段删除了就能显示所有的网卡 ...
https://bbs.deepin.org/post/149000
昨晚上已经可以显示了,电脑的网卡字段不一样,改一下就可以了
https://bbs.deepin.org/post/149000
我昨晚在这个基础上写了一个,看看有没有效果。谢谢。
源码地址:http://www.myzhenai.com.cn/post/2842. ...

https://bbs.deepin.org/post/149000
我先拔下来研究研究!!肯定还有问题需要咨询你!希望到时候不要嫌我烦,哈哈!!!
哭了,为毛我运行的时 ...
https://bbs.deepin.org/post/149000
我没有用过conky,不知道如何, 你可以先在终端里运行这个脚本试试, 将脚本保存为 ip.sh
sh ip.sh
或者
https://bbs.deepin.org/post/149000
就是在终端里运行就报语法错误
#! /bin/bash
#***************************************************************************************************************************************************#
# Author: RucLinux #
# Web: http://www.myzhenai.com.cn http://www.myzhenai.com http://www.haikou-china.com http://jiayu.mybabya.com #
#***************************************************************************************************************************************************#
#网卡接口
indx=$(ifconfig -a|grep encap|awk -F " " '{ print $1 }')
OLD_IFD="$IFD"
IFD=" "
arr=${indx}
IFD="$OLD_IFD"
for d in ${arr[@]}
do
na=$(echo ${d:0:3})
if [ ${na} == "eth" ]; then
name=$(ethtool -i ${d}|grep driver:|awk -F "driver:" '{ print $2 }')
txqueuelen=$(ethtool ${d}|grep Speed:|awk -F "Speed:" '{ print $2 }')
mac=$(ifconfig ${d} | sed -n '/HWaddr/ s/^.*HWaddr *//pg')
fi
ma=${arr[@]}:
md=$(echo ${ma}|sed 's/:/ /g')
done
#ip=`ifconfig | awk -F'[ ]+|:' '/inet addr/{if($4!~/^192.168|^172.16|^10|^127|^0/) print $4}'`
#服务器上的多个IP地址
ip=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|awk -F ":" '{ print $2 }')
#子网掩码
mask=$(ifconfig -a|grep ${ip}|awk -F "Mask:" '{ print $2 }')
#默认网关
gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}')
#dns
dns=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
echo 网络名称: ${name}
echo 网卡接口: ${md}
echo ip 地 址: ${ip}
echo 子网掩码: ${mask}
#echo 广播地址: $broadcast
echo 默认网关: ${gateway}
echo 首选 DNS: ${dns}
echo MAC 地址: ${mac}
echo 网卡速率: ${txqueuelen}
https://bbs.deepin.org/post/149000
对不起,是我书写代码时候不严谨,脚本的文件头是错的。 在Red Hat的发行版里 bash文件的文件头可以使用 ...

https://bbs.deepin.org/post/149000
哦,好的,感谢你耐心指导!
不过现在又有一个问题:
https://bbs.deepin.org/post/149000
这种情况我也不知道, 基本上Linux里的一些组件和代码是一样的,不一样的也就是那么几种。deepin是基于de ...
https://bbs.deepin.org/post/149000
研究了一下,Red Hat系和Debian系的一些命令不一样,导致你的脚本在我这里无法正常运行,比如“ethtool” ...
Popular Ranking
ChangePopular Events
More