更新代码
This commit is contained in:
@@ -79,44 +79,3 @@ void AppData::saveData(const QString &data)
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppData::loadIP(QComboBox *cbox)
|
|
||||||
{
|
|
||||||
//获取本机所有IP
|
|
||||||
static QStringList ips;
|
|
||||||
if (ips.count() == 0) {
|
|
||||||
#ifdef Q_OS_WASM
|
|
||||||
ips << "127.0.0.1";
|
|
||||||
#else
|
|
||||||
QList<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces();
|
|
||||||
foreach (const QNetworkInterface &netInterface, netInterfaces) {
|
|
||||||
//移除虚拟机和抓包工具的虚拟网卡
|
|
||||||
QString humanReadableName = netInterface.humanReadableName().toLower();
|
|
||||||
if (humanReadableName.startsWith("vmware network adapter") || humanReadableName.startsWith("npcap loopback adapter")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//过滤当前网络接口
|
|
||||||
bool flag = (netInterface.flags() == (QNetworkInterface::IsUp | QNetworkInterface::IsRunning | QNetworkInterface::CanBroadcast | QNetworkInterface::CanMulticast));
|
|
||||||
if (flag) {
|
|
||||||
QList<QNetworkAddressEntry> addrs = netInterface.addressEntries();
|
|
||||||
foreach (QNetworkAddressEntry addr, addrs) {
|
|
||||||
//只取出IPV4的地址
|
|
||||||
if (addr.ip().protocol() == QAbstractSocket::IPv4Protocol) {
|
|
||||||
QString ip4 = addr.ip().toString();
|
|
||||||
if (ip4 != "127.0.0.1") {
|
|
||||||
ips << ip4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
cbox->clear();
|
|
||||||
cbox->addItems(ips);
|
|
||||||
if (!ips.contains("127.0.0.1")) {
|
|
||||||
cbox->addItem("127.0.0.1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ public:
|
|||||||
|
|
||||||
//保存数据到文件
|
//保存数据到文件
|
||||||
static void saveData(const QString &data);
|
static void saveData(const QString &data);
|
||||||
|
|
||||||
//添加网卡IP地址到下拉框
|
|
||||||
static void loadIP(QComboBox *cbox);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPDATA_H
|
#endif // APPDATA_H
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ void QtHelper::initLocalIPs(QComboBox *cbox, const QString &defaultIP, bool loca
|
|||||||
{
|
{
|
||||||
QStringList ips;
|
QStringList ips;
|
||||||
if (local127) {
|
if (local127) {
|
||||||
ips << "127.0.0.1";
|
ips << "0.0.0.0" << "127.0.0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加本地网卡地址集合
|
//添加本地网卡地址集合
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void frmTcpClient::initForm()
|
|||||||
//填充数据到下拉框
|
//填充数据到下拉框
|
||||||
ui->cboxInterval->addItems(AppData::Intervals);
|
ui->cboxInterval->addItems(AppData::Intervals);
|
||||||
ui->cboxData->addItems(AppData::Datas);
|
ui->cboxData->addItems(AppData::Datas);
|
||||||
AppData::loadIP(ui->cboxBindIP);
|
QtHelper::initLocalIPs(ui->cboxBindIP, AppConfig::TcpBindIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void frmTcpClient::initConfig()
|
void frmTcpClient::initConfig()
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void frmTcpServer::initForm()
|
|||||||
//填充数据到下拉框
|
//填充数据到下拉框
|
||||||
ui->cboxInterval->addItems(AppData::Intervals);
|
ui->cboxInterval->addItems(AppData::Intervals);
|
||||||
ui->cboxData->addItems(AppData::Datas);
|
ui->cboxData->addItems(AppData::Datas);
|
||||||
AppData::loadIP(ui->cboxListenIP);
|
QtHelper::initLocalIPs(ui->cboxListenIP, AppConfig::TcpListenIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void frmTcpServer::initConfig()
|
void frmTcpServer::initConfig()
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ void frmUdpClient::initForm()
|
|||||||
//填充数据到下拉框
|
//填充数据到下拉框
|
||||||
ui->cboxInterval->addItems(AppData::Intervals);
|
ui->cboxInterval->addItems(AppData::Intervals);
|
||||||
ui->cboxData->addItems(AppData::Datas);
|
ui->cboxData->addItems(AppData::Datas);
|
||||||
AppData::loadIP(ui->cboxBindIP);
|
QtHelper::initLocalIPs(ui->cboxBindIP, AppConfig::UdpBindIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void frmUdpClient::initConfig()
|
void frmUdpClient::initConfig()
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void frmUdpServer::initForm()
|
|||||||
//填充数据到下拉框
|
//填充数据到下拉框
|
||||||
ui->cboxInterval->addItems(AppData::Intervals);
|
ui->cboxInterval->addItems(AppData::Intervals);
|
||||||
ui->cboxData->addItems(AppData::Datas);
|
ui->cboxData->addItems(AppData::Datas);
|
||||||
AppData::loadIP(ui->cboxListenIP);
|
QtHelper::initLocalIPs(ui->cboxListenIP, AppConfig::UdpListenIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void frmUdpServer::initConfig()
|
void frmUdpServer::initConfig()
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void frmWebServer::initForm()
|
|||||||
//填充数据到下拉框
|
//填充数据到下拉框
|
||||||
ui->cboxInterval->addItems(AppData::Intervals);
|
ui->cboxInterval->addItems(AppData::Intervals);
|
||||||
ui->cboxData->addItems(AppData::Datas);
|
ui->cboxData->addItems(AppData::Datas);
|
||||||
AppData::loadIP(ui->cboxListenIP);
|
QtHelper::initLocalIPs(ui->cboxListenIP, AppConfig::WebListenIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void frmWebServer::initConfig()
|
void frmWebServer::initConfig()
|
||||||
|
|||||||
Reference in New Issue
Block a user