KySdkNetCard(3) KySdk Network Card Library KySdkNetCard(3)

KySdkNetCard - D-Bus signal class for generating network card information

#include <kysdkdbus.h>

Inherits from QObject.

KySdkNetCard class is mainly used to generate D-Bus signals for network card information, including getting network card list, MAC address, IP address, subnet mask, gateway, DNS servers, connection status, speed, duplex mode, and other network interface information.

QStringList getNetCardList () const

Get the list of all network cards.

Return value:

List of network card names

QString getNetCardMacAddress (const QString cardName) const

Get the MAC address of the specified network card.

Parameters:

Network card name

Return value:

MAC address of the network card

QString getNetCardIpAddress (const QString cardName) const

Get the IP address of the specified network card.

Parameters:

Network card name

Return value:

IP address of the network card

QString getNetCardSubnetMask (const QString cardName) const

Get the subnet mask of the specified network card.

Parameters:

Network card name

Return value:

Subnet mask of the network card

QString getNetCardGateway (const QString cardName) const

Get the gateway of the specified network card.

Parameters:

Network card name

Return value:

Gateway of the network card

QStringList getNetCardDnsServers (const QString cardName) const

Get the DNS servers of the specified network card.

Parameters:

Network card name

Return value:

DNS server addresses list

bool isNetCardConnected (const QString cardName) const

Check if the specified network card is connected.

Parameters:

Network card name

Return value:

Connection status (true if connected, false otherwise)

int getNetCardSpeed (const QString cardName) const

Get the speed of the specified network card.

Parameters:

Network card name

Return value:

Speed of the network card in Mbps

QString getNetCardDuplexMode (const QString cardName) const

Get the duplex mode of the specified network card.

Parameters:

Network card name

Return value:

Duplex mode ("full", "half", or "unknown")

#include <kysdkdbus.h>
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    KySdkNetCard netCardInfo;
    // Get network card list
    QStringList netCards = netCardInfo.getNetCardList();
    qDebug() << "Network cards:" << netCards;
    // Get information of the first network card
    if (!netCards.isEmpty()) {
        QString cardName = netCards.first();
        QString macAddr = netCardInfo.getNetCardMacAddress(cardName);
        QString ipAddr = netCardInfo.getNetCardIpAddress(cardName);
        QString subnetMask = netCardInfo.getNetCardSubnetMask(cardName);
        QString gateway = netCardInfo.getNetCardGateway(cardName);
        QStringList dnsServers = netCardInfo.getNetCardDnsServers(cardName);
        bool isConnected = netCardInfo.isNetCardConnected(cardName);
        int speed = netCardInfo.getNetCardSpeed(cardName);
        QString duplexMode = netCardInfo.getNetCardDuplexMode(cardName);
        qDebug() << "Network card:" << cardName;
        qDebug() << "  MAC Address:" << macAddr;
        qDebug() << "  IP Address:" << ipAddr;
        qDebug() << "  Subnet Mask:" << subnetMask;
        qDebug() << "  Gateway:" << gateway;
        qDebug() << "  DNS Servers:" << dnsServers;
        qDebug() << "  Connected:" << isConnected;
        qDebug() << "  Speed:" << speed << "Mbps";
        qDebug() << "  Duplex Mode:" << duplexMode;
    }
    return 0;
}

  • IP address, subnet mask, and gateway are returned as string format
  • DNS servers are returned as a list of string addresses
  • Speed is returned in Mbps (Megabits per second)
  • Duplex mode can be "full", "half", or "unknown"
  • Connection status returns true if the network card is active and connected

QObject(3qt5), D-Bus(1), ifconfig(8), ip(8), nmcli(1)

Generated automatically by Doxygen for kysdkdbus.h from the source code.

Wed Sep 20 2023 1.0