network help script

In EAVCapture project,I need to display wired and wireless network information in Qt GUI,but the Qt's Network Library is not good to get these data,so I wrote a simple script to archive this.The code was attached following.

I use QProgress to execute external scripts,and get its output.

I hope this script can help others.

Enjoy,guys!


#!/bin/bash


#this script is used to get network interface information,
#contains wired and wireless.
#at default,
#the wired name is eth0,
#the wireless name is wlan0.
#if the names are not adapted,please change them.
#May 19,2015 by zhangshaoyan.(13522296239)

#define the wired and wireless network interface name.
WIREDNAME=enp8s0
WIRELESSNAME=wlp5s0

#define the used utilties absolutely path.
#it is very important here!!!
IFCONFIG=/sbin/ifconfig
AWK=/usr/bin/awk

#the call format is
#./ZNetworkHelp.sh wired ip/mac/mask
#./ZNetworkHelp.sh wireless ip/mac/mask
if [ $# -lt 2 ];then
    echo "Missing Parameter"
    exit -1
fi

#get the network interface name.
NetworkName=${WIREDNAME}
if [ $1 = "wired" ];then
    NetworkName=${WIREDNAME}
elif [ $1 = "wireless" ];then
    NetworkName=${WIRELESSNAME}
else
    echo "Invalid NICName"
    exit -1
fi

#get ip/mac/mask.
if [ $2 = "ip" ];then
    ${IFCONFIG} ${NetworkName} | ${AWK} '/inet addr:/{print $2}' | ${AWK} -F: '{print $2}'
elif [ $2 = "mask" ];then
    ${IFCONFIG} ${NetworkName} | ${AWK} -F : '/Mask/{print $4}'
elif [ $2 = "mac" ];then
    ${IFCONFIG} ${NetworkName} | ${AWK} '/HWaddr/{print $5}'
else
    echo "Invalid Command"
    exit -1
fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值