- 系统: win10
- IDE: QT(Qt Quick)
命令查看
cmd中输入netstat -nao
;
代码
QStringList getSystemPort()
{
QProcess pro;
pro.start("netstat -nao");
pro.waitForStarted(); //等待程序开始
pro.waitForFinished(); //等待程序结束
QString str(pro.readAllStandardOutput().data());
QStringList strList = str.split("\n",QString::SkipEmptyParts);
QStringList strListPort;
for(int i = 0; i < strList.count(); ++i)
{
QString strTemp(strList[i]);
if(strTemp.contains("TCP [::]:"))
{
strTemp = strTemp.remove(QRegExp("\\s"));//去除所有空格
int indexFirst = strTemp.indexOf("]:");
strTemp = strTemp.mid(indexFirst + 2);
indexFirst = strTemp.indexOf("[:");
strTemp = strTemp.left(indexFirst);
strListPort.append(strTemp);
}
}
return strListPort;
}
strListPort值