#include "module4g.h" module4g::module4g(QObject *parent) : QObject(parent) { eth1_ip_kong = false;//网线ip状态判断 eth1_line_lan_flag = true; times = 0; QTimer::singleShot(1000, this, SLOT(onTimerTimeOutPing4g())); } void module4g::onTimerTimeOutPing4g() { qDebug("ping 4g: timeout 5s ping -I ppp0 202.108.22.5 > /home/data/4g_quailty"); std::system("timeout 5s ping -I ppp0 www.baidu.com -n > /home/data/4g_quailty"); QTimer::singleShot(5000, this, SLOT(onTimerTimeOutCheck4g())); } void module4g::onTimerTimeOutCheck4g() { QFile file_read_net("/home/data/4g_quailty"); QString net_check = ""; bool flag_4g = false; if(file_read_net.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file_read_net);//创建一个对象让它去读文件 QString ping1=in.readLine(); QString ping2=in.readLine(); net_check=ping2.left(2); } file_read_net.close(); if (net_check=="64") { flag_4g = true; } else { flag_4g = false; } emit sig4gstate(flag_4g); QString line_4G_ip = ""; if(flag_4g == false) { times = times +1; if(times > 20) { times = 0; std::system("/home/4G_reset.sh &"); std::system("ifconfig ppp0 | grep \"inet addr\" | awk '{ print $2}' | awk -F: '{print $2}' > /home/4G_IP"); QFile file_read_gip("/home/4G_IP"); if(file_read_gip.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file_read_gip);//创建一个对象让它去读文件 line_4G_ip=in.readLine(); } file_read_gip.close(); if(line_4G_ip == "") { }else{ QString IP_4G_set="route add default gw "+line_4G_ip; QString IP_4G_reset="route del default gw "+line_4G_ip; std::system(IP_4G_reset.toLatin1()); std::system(IP_4G_set.toLatin1()); } } } QFile file_write_Lan("/home/LAN_IP"); int count = 0; bool flag_lan = false; QString line_lan_ip = ""; QList netList = QNetworkInterface::allInterfaces(); foreach(QNetworkInterface net,netList)//遍历每一个接口信息 { if(net.name() == "eth1"){ count++; QList entryList = net.addressEntries();//获取ip地址和子网掩码和广播地址 if(entryList.isEmpty()) { flag_lan = false; if(!file_write_Lan.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { qDebug()<<"文件清空失败"; } file_write_Lan.close(); }else{ flag_lan = true; foreach(QNetworkAddressEntry entry,entryList)//遍历ip条目列表 { if(entry.ip().protocol() == QAbstractSocket::IPv4Protocol){ if(file_write_Lan.open(QIODevice::WriteOnly)) { QTextStream setWIFI_data(&file_write_Lan); setWIFI_data<