OK335xS Qt network hacking
/**********************************************************************
* OK335xS Qt network hacking
* 说明:
* 应该半年前尝试过来解读这个程序,但是那时候对有些东西不是很理解,
* 最后不了了之了,这次因为需要,所以重新对network的mainwindow.cpp进行
* 一下解读。
*
* 2016-4-8 深圳 南山平山村 曾剑锋
*********************************************************************/ #include "mainwindow.h"
#include "ui_mainwindow.h" // ifconfig -a|grep -E "eth[0-9]|wlan[0-9]"|cut -d' ' -f 1
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// 设置UI界面
ui->setupUi(this);
proc = NULL;
flag = false;
// 选择的网卡发生了改变
connect(ui->cb_interface, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(on_sel_changed(QString)));
// 点击了OK按j钮
connect(ui->ok, SIGNAL(clicked()), this, SLOT(on_ok_clicked()));
// 选择了dhcp单选按钮
connect(ui->radio_dhcp, SIGNAL(toggled(bool)), this, SLOT(on_toggled(bool)));
// 选择了static单选按钮
connect(ui->radio_static, SIGNAL(toggled(bool)), this, SLOT(on_toggled(bool))); // 获取当前系统中的网卡,并创建对应的网卡实例
refreshInterfaces();
// 读取当前系统默认对网卡的配置
readConfigs(); // 将当前默认的网卡的数据显示
on_sel_changed(ui->cb_interface->currentText()); } MainWindow::~MainWindow()
{
delete ui;
// 释放实例化的网卡实例
foreach(Interface *i,ints)
delete i;
} void MainWindow::state(bool dhcp)
{
// 设置UI显示状态
if(dhcp)
{
ui->radio_dhcp->setChecked(true);
ui->radio_static->setChecked(false);
ui->edt_ip->setDisabled(true);
ui->edt_mask->setDisabled(true);
ui->edt_gateway->setDisabled(true);
ui->edt_dns->setDisabled(true);
}
else
{
ui->radio_dhcp->setChecked(false);
ui->radio_static->setChecked(true);
ui->edt_ip->setDisabled(false);
ui->edt_mask->setDisabled(false);
ui->edt_gateway->setDisabled(false);
ui->edt_dns->setDisabled(false);
}
} void MainWindow::refreshInterfaces()
{
QStringList sl; /*过滤读eth[0-9] wlan[0-9]*/
// 获取网卡名保存在/tmp/interfaces文件中,一行一个网卡名
::system("ifconfig -a|grep -E \"eth[0-9]\"|cut -d' ' -f 1 >/tmp/interfaces");
// 打开缓存文件
QFile f("/tmp/interfaces");
if(f.open(QFile::ReadOnly))
{
// 创建文件流
QTextStream t(&f);
// 判断是否到了文件末尾
while(!t.atEnd())
{
// 获取一行,也就是一个网卡名
QString str=t.readLine();
if(str.size()>)
{
//QMessageBox::about(this,"aaa",str);
/**
* 1. QList<Interface*> ints;
* 2. class Interface
* {
* public:
* Interface(QString &name);
* public:
* QString name;
* bool dhcp;
* QString ip;
* QString mask;
* QString gateway;
* QString dns;
* };
* 3. 实例化网卡,添加在list后面
* 4. 与后面的c_interface的index是一样的
*
*/
ints.append(new Interface(str));
sl<<str;
}
}
}
f.close(); ui->cb_interface->addItems(sl);
} void MainWindow::readConfigs()
{
/*自己的配置文件*/
foreach(Interface *i,ints)
{
// 获取几个网卡的默认配置信息
QFile f("/etc/network/.conf/"+i->name);
if(f.open(QFile::ReadOnly))
{
QTextStream t(&f);
QString str = t.readLine(); if(str == "dhcp")//do nothing
;
// 从下面的内容可以知道,配置信息的循序必须按照下面读取的顺序进行排序写,
// 否则会照成配置出错
else if(str == "static")
{
i->dhcp = false;
i->ip = t.readLine();
i->mask = t.readLine();
i->gateway = t.readLine();
i->dns = t.readLine();
}
}
f.close();
}
} /**
* @brief ip2int
* @param ip
* @return
*
* 将IP地址转化成整数
*/
unsigned int ip2int(QString ip)
{
QStringList sl = ip.split('.');
unsigned int r = ;
foreach(QString s,sl)
{
r <<= ;
r |= s.toUInt();
} return r;
} /**
* @brief int2ip
* @param ip
* @return
*
* 将int型整数,转化成点分十进制IP
*/
QString int2ip(unsigned int ip)
{
return QString::number((ip >> ) & 0xff) + "." + QString::number((ip >> ) & 0xff)
+ "." + QString::number((ip >> ) & 0xff) + "." + QString::number(ip & 0xff);
} void MainWindow::writeConfigs()
{
/*真正的配置文件*/
// 域名服务器IP
::system("rm /etc/resolv.conf");
QFile r("/etc/resolv.conf");//for dns
QTextStream *t2 = NULL;
if(r.open(QFile::WriteOnly))
{
t2 = new QTextStream(&r);
} // 网卡参数
QFile m("/etc/network/interfaces");//for interface
QTextStream *t3 = NULL;
if(m.open(QFile::WriteOnly))
{
t3 = new QTextStream(&m);
} /*write `lo` configration first*/
*t3<<QString("auto lo\n");
*t3<<QString("iface lo inet loopback\n"); ::system("mkdir -p /etc/network/.conf"); /*自己的配置文件*/
// 重写配置文件
foreach(Interface *i,ints)
{
QFile f("/etc/network/.conf/"+i->name); if(f.open(QFile::WriteOnly))
{
QTextStream t(&f); if(i->dhcp)
{
t<<QString("dhcp")<<QString(QString("\n"));
*t3<<QString("auto ")<<i->name<<QString(QString("\n"));
*t3<<QString("iface ")<<i->name<<QString(" inet dhcp\n");
}
else
{
t<<QString("static")<<QString("\n");
t<<i->ip<<QString("\n");
t<<i->mask<<QString("\n");
t<<i->gateway<<QString("\n");
t<<i->dns<<QString("\n"); *t3<<QString("auto ")<<i->name<<QString("\n");
*t3<<QString("iface ")<<i->name<<QString(" inet static\n");
*t3<<QString("address ")<<i->ip<<QString("\n");
*t3<<QString("netmask ")<<i->mask<<QString("\n");
*t3<<QString("gateway ")<<i->gateway<<QString("\n");
*t3<<QString("broadcast ")<<int2ip((ip2int(i->ip) & ip2int(i->mask))|(~ip2int(i->mask)))<<QString("\n"); *t2<<QString("nameserver ")+i->dns<<QString("\n");//同时写入到/etc/resolv.conf
}
}
f.close();
} delete t2;
delete t3; r.close();
m.close();
} void MainWindow::on_toggled(bool b)
{
// 通过这里知道当前索引的那张网卡
Interface *i = NULL;
foreach(i,ints)
{
if(i->name == ui->cb_interface->currentText())
break;
} // 根据当前的是否采用dhcp还是static来显示UI控件
state(ui->radio_dhcp->isChecked()); // 显示对应的数据
if(ui->radio_dhcp->isChecked())
{
/*ui->edt_ip->clear();
ui->edt_mask->clear();
ui->edt_gateway->clear();
ui->edt_dns->clear();*/
}
else
{
ui->edt_ip->setText(i->ip);
ui->edt_mask->setText(i->mask);
ui->edt_gateway->setText(i->gateway);
ui->edt_dns->setText(i->dns);
}
} void MainWindow::on_sel_changed(const QString &text)
{
// 循环检查,如果当前次循环的网卡实例名与传入的参数一样,那么跳出循环,
// i则指向了当前需要配置的网卡
Interface *i = NULL;
foreach(i,ints)
{
if(i->name == text)
break;
} //QMessageBox::about(this,"aaa",i->name); // 设置UI显示状态
state(i->dhcp); // 重新设置UI中的值
if(i->dhcp)
{
ui->edt_ip->clear();
ui->edt_mask->clear();
ui->edt_gateway->clear();
ui->edt_dns->clear();
}
else
{
ui->edt_ip->setText(i->ip);
ui->edt_mask->setText(i->mask);
ui->edt_gateway->setText(i->gateway);
ui->edt_dns->setText(i->dns);
}
} void MainWindow::on_ok_clicked()
{
// 获取当前的网jjj卡
Interface *i = NULL;
foreach(i,ints)
{
if(i->name == ui->cb_interface->currentText())
break;
} // 设置当前的网卡
i->dhcp = ui->radio_dhcp->isChecked();
i->ip = ui->edt_ip->text();
i->mask = ui->edt_mask->text();
i->gateway = ui->edt_gateway->text();
i->dns = ui->edt_dns->text(); // 写入文件
writeConfigs();
// 同步,将内存中的数据写入NAND或者SD卡
::system("sync"); // 如果proc存在,那么就释放
if(proc)
delete proc; // 创建进程来重启网卡
proc = new QProcess(this);
proc->start("/etc/init.d/networking restart");
// 防止进程未处理完之前,程序退出
connect(proc,SIGNAL(finished(int)),this,SLOT(proc_finished(int)));
this->setDisabled(true); flag = true;
} void MainWindow::closeEvent(QCloseEvent * evt)
{
if(flag)
{
evt->ignore();
QMessageBox::about(this,"info","network is restarting,please wait");
}
else
{
destroy();
exit();
}
} void MainWindow::moveEvent(QMoveEvent *)
{
this->move(QPoint(,));
} void MainWindow::resizeEvent(QResizeEvent *)
{
this->showMaximized();
} void MainWindow::proc_finished(int code)
{
if(proc->exitStatus() == QProcess::NormalExit)
{
this->setDisabled(false);
flag = false;
QMessageBox::about(this,"info","network restart ok!");
}
}
OK335xS Qt network hacking的更多相关文章
- OK335xS mac address hacking
/*********************************************************************** * OK335xS mac address hacki ...
- OK335xS EMMC Partition hacking
#! /bin/sh # # OK335xS EMMC Partition hacking # 说明: # 本文主要是为了解读同事对EMMC分区的写法,其中有很多写法重复了,但 # 依然尽量保留其作者 ...
- 解决Qt5使用SSL的“qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method”错误
在使用Qt的网络组件连接某些服务器时, 会提示"qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method"的错误 ...
- qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
使用Qt编写程序访问知乎官网,程序报错 qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method ...
- QT4.8.6之qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
想试着用qt写一个爬虫,编译的时候报如下错误 qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error qt. ...
- OK335xS knob driver hacking
/************************************************************************* * OK335xS knob driver hac ...
- Top 10 Free Wireless Network hacking/monitoring tools for ethical hackers and businesses
There are lots of free tools available online to get easy access to the WiFi networks intended to he ...
- Qt NetWork即时通讯网络聊天室(基于TCP)
本文使用QT的网络模块来创建一个网络聊天室程序,主要包括以下功能: 1.基于TCP的可靠连接(QTcpServer.QTcpSocket) 2.一个服务器,多个客户端 3.服务器接收到某个客户端的请求 ...
- 解决qt提示:qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
方法一(解决):把C:\Qt\Qt5.8.0\Tools\QtCreator\bin下的libeay32.dll和ssleay32.dll库复制到C:\Qt\Qt5.8.0\5.8\msvc2015_ ...
随机推荐
- 1 server - n clients 模型实现(select)
拓扑结构: 各个客户端创建读写管道,通过“上下线信息管道”向服务器发送上下线信息和读写管道名称.服务器接受信息,修改链表(存储客户端信息).客户端.服务器打开读写管道,服务器通过“W”管道接收从客户端 ...
- Jsonp 跨域请求实例
关于jsonp的一个实例,其实自己也不是很了解,今天下午稍微研究了一下: 简单来说,jsonp就是为了两个不同网站之间数据传递而产生的,主要用于js脚本,因为浏览器本身是禁止跨域访问的: 本机实例: ...
- Keil V4.72升级到V5.1X之后
问题描述 Keil V4.72升级到V5.1x之后,原来编译通过的工程,出现了如下错误: .\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\STM32f ...
- Mac OS X 10.10 Yosemite PHP 5.5.14 free type support fix
通过将php将至5.4来勉强支持freetype扩展,不推荐此方法 after upgrading to new Mac OS X Yosemite, i noticed that free type ...
- (转载)Cocos2dx-OpenGL ES2.0教程:编写自己的shader(2)
在上篇文章中,我给大家介绍了如何在cocos2d-x里面绘制一个三角形,当时我们使用的是cocos2d-x引擎自带的shader和一些辅助函数.在本文中,我将演示一下如何编写自己的shader,同时, ...
- js获取当前浏览器页面高度及宽度信息的方法
var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); var scroll ...
- DirectX考试判卷心得
今天帮老师判<三维图形程序设计>的试卷,这门课开卷考,用的教材是段菲翻译的DX9的龙书.判卷过程中发现有两道题虽然不难,但是错的比较多: 1.Direct3D中深度缓冲区中值的范围? A. ...
- PAT-乙级-1041. 考试座位号(15)
1041. 考试座位号(15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 每个PAT考生在参加考试时都会被分 ...
- 团体程序设计天梯赛-练习集L1-011. A-B
L1-011. A-B 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 本题要求你计算A-B.不过麻烦的是,A和B都是字符串 — ...
- PHP截取字符串,获取长度,获取字符位置的函数
strstr(string,string) = strchr(,) //从前面第一次出现某个字符串的地方截取到最后strrchr(string,string) //从某个字符串从最后出现的位置截取到结 ...