QT获取本机IP和Mac地址
#include <QNetworkInterface>
#include <QList> void MainWindow::getIPPath()
{ QString strIpAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // 获取第一个本主机的IPv4地址 int nListSize = ipAddressesList.size(); for (int i = 0; i < nListSize; ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address())
{ strIpAddress = ipAddressesList.at(i).toString(); break; } } // 如果没有找到,则以本地IP地址为IP if (strIpAddress.isEmpty())
{
qDebug() << strIpAddress;
strIpAddress = QHostAddress(QHostAddress::LocalHost).toString();
}
qDebug() << "IP:" << strIpAddress;
} void MainWindow::getMacPath()
{
QList<QNetworkInterface> nets = QNetworkInterface::allInterfaces();// 获取所有网络接口列表 int nCnt = nets.count(); QString strMacAddr = ""; for(int i = 0; i < nCnt; i ++) { // 如果此网络接口被激活并且正在运行并且不是回环地址,则就是我们需要找的Mac地址 if(nets[i].flags().testFlag(QNetworkInterface::IsUp) && nets[i].flags().testFlag(QNetworkInterface::IsRunning) && !nets[i].flags().testFlag(QNetworkInterface::IsLoopBack)) { strMacAddr = nets[i].hardwareAddress(); break; } }
qDebug() << "Mac:" << strMacAddr;
}
QT获取本机IP和Mac地址的更多相关文章
- 获取本机IP、mac地址、计算机名
python获取本机IP.mac地址.计算机名 在python中获取ip地址和在php中有很大不同,我们先来看一下python 获得本机MAC地址: >>> import uuid ...
- python获取本机IP、mac地址、计算机名
在python中获取ip地址和在php中有很大不同,在php中往往比较简单.那再python中怎么做呢? 我们先来看一下python 获得本机MAC地址: 1 2 3 4 import uuid de ...
- Linux 获取本机IP、MAC地址用法大全
getifaddrs()和struct ifaddrs的使用,获取本机IP ifaddrs结构体定义如下: struct ifaddrs { struct ifaddrs *ifa_next; /* ...
- JAVA获取本机IP和Mac地址
在项目中,时常需要获取本机的Ip或是Mac地址,进行身份和权限验证,本文就是通过java代码获取ip和Mac. package com.svse.query;import java.net.In ...
- ioctrl 获取本机IP及MAC地址
通过使用ioctl可以获得本机的一些信息,这里记录获得interface IP及MAC的过程. 1:ioctl 函数的作用是什么 man ioctl: DESCRIPTION The ioctl() ...
- java 获取本机ip及mac地址
package com.achun.test; import java.net.Inet4Address;import java.net.Inet6Address;import java.net.In ...
- c#中如何获取本机用户名、MAC地址、IP地址、硬盘ID、CPU序列号、系统名称、物理内存
我们在利用C#开发桌面程序(Winform)程序的时候, 经常需要获取一些跟系统相关的信息, 以下这些代码获取能有些用处. c#中如何获取本机用户名.MAC地址.IP地址.硬盘ID.CPU序列号.系统 ...
- Qt获取本机IP地址
Qt获取本机IP地址: Qt版本:4.8.6 #include <QtNetwork/QNetworkInterface.h> QString ipAddr; QList<QHost ...
- qt获取本机ip
//获取本机IP QString getIP(QString localHost) { QString ipAddr; #if 0 QList<QHostAddress> AddressL ...
随机推荐
- [Swift]LeetCode155. 最小栈 | Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- [Swift]LeetCode276. 粉刷栅栏 $ Paint Fence
There is a fence with n posts, each post can be painted with one of the k colors. You have to paint ...
- [Swift]LeetCode433. 最小基因变化 | Minimum Genetic Mutation
A gene string can be represented by an 8-character long string, with choices from "A", &qu ...
- [Swift]LeetCode434. 字符串中的单词数 | Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
- [Swift]LeetCode498. 对角线遍历 | Diagonal Traverse
Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal ...
- [Swift]LeetCode976. 三角形的最大周长 | Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, ...
- 【Spark篇】---Spark资源调度和任务调度
一.前述 Spark的资源调度是个很重要的模块,只要搞懂原理,才能具体明白Spark是怎么执行的,所以尤其重要. 自愿申请的话,本文分粗粒度和细粒度模式分别介绍. 二.具体 Spark资源调度流程图: ...
- Python内置函数(61)——str
英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string ...
- python +selenium识别不来click事件,出现报错
assert "login" in browser.title browser.implicitly_wait(10) elem = browser.find_element_by ...
- Python爬虫入门教程 14-100 All IT eBooks多线程爬取
All IT eBooks多线程爬取-写在前面 对一个爬虫爱好者来说,或多或少都有这么一点点的收集癖 ~ 发现好的图片,发现好的书籍,发现各种能存放在电脑上的东西,都喜欢把它批量的爬取下来. 然后放着 ...