[Tutorials] 乱七八糟的脚本 判断网络状态 更新 和Linux发行版
Tofloor
poster avatar
酷谷的谷子
deepin
2022-04-19 05:45
Author

乱七八糟的脚本 判断网络状态 更新 和Linux发行版

排版很乱 凑合看 凑合用 有时候我喜欢在一个脚本输出 好几个脚本 这样不会有太多零星的脚本

安装sudo apt install deepin-wine-helper 这个会安装 zenity

基本硬件检测.zip python-http-server.sh.zip

深度截图_选择区域_20220505134909.png

深度截图_选择区域_20220505135050.png

#!/bin/bash
#只适用于有一个无线网卡 和一个集成网卡的 电脑
#获取LINUX发行版 只支持显示 Mint Deepin 需要判断更多可以自己修改
Get_Dist_Name()
{
if grep -Eqi "Mint" /etc/issue || grep -Eq "Mint" /etc/*-release; then
DISTRO='Mint'
PM='apt'
elif grep -Eqi "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; then
DISTRO='Deepin'
PM='apt'
else
DISTRO='没有匹配到'
fi
echo $DISTRO;
}
Get_Dist_NameX=$(Get_Dist_Name)
#END-获取LINUX发行版 只支持显示 Mint Deepin 需要判断更多可以自己修改

#获得外网IP
WAIWANG_X=$(curl -s http://www.net.cn/static/customercare/yourip.asp | grep -P -o "[0-9.]+(?=)")

#获得独显信息
VGA_X=`lspci |grep VGA`
ECHO_VGA_X=`echo ${VGA_X#*Inc.}`

#获得CPU 基本信息
CPU_X=`cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c`
ECHO_CPU_X="`echo CPU基本信息: 线程数${CPU_X:5:50}`"

#获得网卡基本信息
AUDIO_X_A_A=`aplay -l|grep card| sed -n 1p`
AUDIO_X_A_B=`aplay -l|grep card| sed -n 2p`
AUDIO_X_A=`aplay -l|grep card|wc -l`
AUDIO_X_B="2"
MY_AUDIO_()
{
if [ ! $AUDIO_X_A = $AUDIO_X_B ];then
echo "声卡基本信息: $AUDIO_X_A_A"
else
echo "声卡基本信息: $AUDIO_X_A_A"
echo "声卡基本信息: $AUDIO_X_A_B"
fi
}
MY_AUDIO_X=$(MY_AUDIO_)
#END-获得网卡基本信息

#判断有没有无线网卡 没有会显示0行 有的话大于等于1行
p_ssid_new=`iwconfig|grep ESSID|wc -l`
p_ssid="0"
#判断是否开启/链接了WIFI没有显示 ESSID:off/any
p_ssid_off_a="off/any"
p_ssid_off_new=`iwconfig|grep ESSID`
p_ssid_off_b=`echo ${p_ssid_off_new#*ESSID} | sed 's/://g' | sed 's/"//g'`
#获取无线网卡名称
P_NAME=`echo ${p_ssid_off_new%IEEE*} | sed 's/ //g'`
#获取MAC地址行数 2行就表示2个mac 第一行就是板载网卡,第二行就是无线网卡
p_mac_new=`ifconfig|grep ether|awk '{print $2}'|wc -l`
p_mac="2"
#排除有线网卡 没有链接网络 与便获得准确的无线网卡IP
MY_WIFI_IP_2_A=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'| sed -n 2p|wc -l`
MY_WIFI_IP_2_B="0"

#查看无线网卡设备--------------------------------------------------------------------------
MY_WIFI()
{
if [ ! $p_ssid_new = $p_ssid ];then
if [ ! $p_ssid_off_b = $p_ssid_off_a ];then
#小于二就说明没有集成网卡
if [ ! $p_mac_new = $p_mac ];then
echo "无线网卡设备: ${P_NAME} MAC: `ifconfig|grep ether|awk '{print $2}'| sed -n 1p`\
 IP: `ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'| sed -n 1p`\
 SSID: $p_ssid_off_b"
else
#在有线 无线 网卡的情况下排除有线网卡没有链接网络
if [ ! $MY_WIFI_IP_2_A = $MY_WIFI_IP_2_B ];then
echo "无线网卡设备: ${P_NAME} MAC: `ifconfig|grep ether|awk '{print $2}'| sed -n 2p`\
 IP: `ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'| sed -n 2p`\
 SSID: $p_ssid_off_b"
else
echo "无线网卡设备: ${P_NAME} MAC: `ifconfig|grep ether|awk '{print $2}'| sed -n 2p`\
 IP: `ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'| sed -n 1p`\
 SSID: $p_ssid_off_b"
fi
#END-在有线 无线 网卡的情况下排除有线网卡没有链接网络
fi
else
echo "没有链接WIFI!"
fi
else
echo "没有无线网卡!"
fi
}
MY_WIFI_X=$(MY_WIFI)

#END-查看无线网卡设备--------------------------------------------------------------------------

#查看有线网卡设备------------------------------------------------------------------------------
YX_shebei()
{
#如果有集成网卡第一行 有网卡设备名称
YX_shebei_A=`ifconfig|sed -n 1p`
YX_shebei_A_NAME=`echo ${YX_shebei_A%flags*}| sed 's/://g'`
#集成网卡一般是en开头
YX_shebei_B="en"
#如果有集成网卡第二行 有可能是IP 开头就是 inet
YX_shebei_F_A=`ifconfig|sed -n 2p|grep inet|awk '{print $2}'`
YX_shebei_F_A_X=`ifconfig|sed -n 2p`
YX_shebei_F_B="inet"
#如果联网第四行是MAC 开头就是 ether
YX_shebei_F_C=`ifconfig|sed -n 4p|grep ether|awk '{print $2}'`
YX_shebei_F_D="ether"

#判断有没有集成网卡
if [[ $YX_shebei_A == *$YX_shebei_B* ]];then
if [[ $YX_shebei_F_A_X == *$YX_shebei_F_B* ]];then
    #集成网卡设备名称 ip MAC
   echo "有线网卡设备: $YX_shebei_A_NAME  MAC: $YX_shebei_F_C  IP: $YX_shebei_F_A"
  
else
    echo "有线上网设备:没有链接网络!"
fi

else
    echo "没有集成网卡!"
fi
}
MY_YX_shebei=$(YX_shebei)
#END-查看有线网卡设备--------------------------------------------------------------------------
#zenity gui 输出显示 结果
zenity --info --icon-name="deepin-screenshot" --width=600  \
--title="基本硬件信息-你的Linux发行版是$Get_Dist_NameX" \
--text="外网IP: $WAIWANG_X\n显卡设备信息: $ECHO_VGA_X\n$ECHO_CPU_X\n$MY_AUDIO_X\n$MY_YX_shebei\n$MY_WIFI_X"
exit 0
Reply Favorite View the author
All Replies
神末shenmo
deepin
Spark-App
Q&A Team
2022-04-19 17:51
#1

我觉着还不错

Reply View the author