获取主机名称
/*
* 名称:get_localmachine_name
* 功能:获取本机机器名称
* 参数:no
* 返回:qstring
*/
qstring cafesclient::get_localmachine_name()
{
qstring machinename = qhostinfo::localhostname();
return machinename;
}
获取本机ip地址
/*
* 名称:get_localmachine_ip
* 功能:获取本机的ip地址
* 参数:no
* 返回:qstring
*/
qstring cafesclient::get_localmachine_ip()
{
qstring ipaddress;
qlist ipaddresseslist = qnetworkinterface::alladdresses();
// use the first non-localhost ipv4 address
for (int i = 0; i < ipaddresseslist.size(); ++i) {
if (ipaddresseslist.at(i) != qhostaddress::localhost &&
ipaddresseslist.at(i).toipv4address()) {
ipaddress = ipaddresseslist.at(i).tostring();
break;
}
}
// if we did not find one, use ipv4 localhost
if (ipaddress.isempty())
ipaddress = qhostaddress(qhostaddress::localhost).tostring();
return ipaddress;
}
获取本机网络连接名、mac地址
/*
* 名称:get_localmachine_mac
* 功能:获取本机的mac地址
* 参数:no
* 返回:void
*/
qstring cafesclient::get_localmachine_mac()
{
qlist nets = qnetworkinterface::allinterfaces();
int i = 0;
foreach(qnetworkinterface ni,nets)
{
i++;
qdebug()<
获取本机子网掩码、广播地址
//在上个函数的环境下
qlist entrylist =interface.addressentries();
//获取ip地址条目列表,每个条目中包含一个ip地址,一个子网掩码和一个广播地址
foreach(qnetworkaddressentry entry,entrylist)
{
//遍历每一个ip地址条目
qdebug()<
“<
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!