QNetworkInterface#

The QNetworkInterface class provides a listing of the host’s IP addresses and network interfaces. More

Inheritance diagram of PySide6.QtNetwork.QNetworkInterface

Synopsis#

Functions#

Static functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

QNetworkInterface represents one network interface attached to the host where the program is being run. Each network interface may contain zero or more IP addresses, each of which is optionally associated with a netmask and/or a broadcast address. The list of such trios can be obtained with addressEntries() . Alternatively, when the netmask or the broadcast addresses or other information aren’t necessary, use the allAddresses() convenience function to obtain just the IP addresses of the active interfaces.

QNetworkInterface also reports the interface’s hardware address with hardwareAddress() .

Not all operating systems support reporting all features. Only the IPv4 addresses are guaranteed to be listed by this class in all platforms. In particular, IPv6 address listing is only supported on Windows, Linux, macOS and the BSDs.

class PySide6.QtNetwork.QNetworkInterface#

PySide6.QtNetwork.QNetworkInterface(other)

Parameters:

otherPySide6.QtNetwork.QNetworkInterface

Constructs an empty network interface object.

Creates a copy of the QNetworkInterface object contained in other.

PySide6.QtNetwork.QNetworkInterface.InterfaceFlag#

(inherits enum.Flag) Specifies the flags associated with this network interface. The possible values are:

Constant

Description

QNetworkInterface.IsUp

the network interface is “up” - enabled by administrative action

QNetworkInterface.IsRunning

the network interface is operational: configured “up” and (typically) physically connected to a network

QNetworkInterface.CanBroadcast

the network interface works in broadcast mode

QNetworkInterface.IsLoopBack

the network interface is a loopback interface: that is, it’s a virtual interface whose destination is the host computer itself

QNetworkInterface.IsPointToPoint

the network interface is a point-to-point interface: that is, there is one, single other address that can be directly reached by it.

QNetworkInterface.CanMulticast

the network interface supports multicasting

Note that one network interface cannot be both broadcast-based and point-to-point.

PySide6.QtNetwork.QNetworkInterface.InterfaceType#

Specifies the type of hardware (PHY layer, OSI level 1) this interface is, if it could be determined. Interface types that are not among those listed below will generally be listed as Unknown, though future versions of Qt may add new enumeration values.

The possible values are:

Constant

Description

QNetworkInterface.Unknown

The interface type could not be determined or is not one of the other listed types.

QNetworkInterface.Loopback

The virtual loopback interface, which is assigned the loopback IP addresses (127.0.0.1, ::1).

QNetworkInterface.Virtual

A type of interface determined to be virtual, but not any of the other possible types. For example, tunnel interfaces are (currently) detected as virtual ones.

QNetworkInterface.Ethernet

IEEE 802.3 Ethernet interfaces, though on many systems other types of IEEE 802 interfaces may also be detected as Ethernet (especially Wi-Fi).

QNetworkInterface.Wifi

IEEE 802.11 Wi-Fi interfaces. Note that on some systems, QNetworkInterface may be unable to distinguish regular Ethernet from Wi-Fi and will not return this enum value.

QNetworkInterface.Ieee80211

An alias for WiFi.

QNetworkInterface.CanBus

ISO 11898 Controller Area Network bus interfaces, usually found on automotive systems.

QNetworkInterface.Fddi

ANSI X3T12 Fiber Distributed Data Interface, a local area network over optical fibers.

QNetworkInterface.Ppp

Point-to-Point Protocol interfaces, establishing a direct connection between two nodes over a lower transport layer (often serial over radio or physical line).

QNetworkInterface.Slip

Serial Line Internet Protocol interfaces.

QNetworkInterface.Phonet

Interfaces using the Linux Phonet socket family, for communication with cellular modems. See the Linux kernel documentation for more information.

QNetworkInterface.Ieee802154

IEEE 802.15.4 Personal Area Network interfaces, other than 6LoWPAN (see below).

QNetworkInterface.SixLoWPAN

6LoWPAN (IPv6 over Low-power Wireless Personal Area Networks) interfaces, which operate on IEEE 802.15.4 PHY, but have specific header compression schemes for IPv6 and UDP. This type of interface is often used for mesh networking.

QNetworkInterface.Ieee80216

IEEE 802.16 Wireless Metropolitan Area Network, also known under the commercial name “WiMAX”.

QNetworkInterface.Ieee1394

IEEE 1394 interfaces (a.k.a. “FireWire”).

PySide6.QtNetwork.QNetworkInterface.addressEntries()#
Return type:

Returns the list of IP addresses that this interface possesses along with their associated netmasks and broadcast addresses.

If the netmask or broadcast address or other information is not necessary, you can call the allAddresses() function to obtain just the IP addresses of the active interfaces.

static PySide6.QtNetwork.QNetworkInterface.allAddresses()#
Return type:

This convenience function returns all IP addresses found on the host machine. It is equivalent to calling addressEntries() on all the objects returned by allInterfaces() that are in the IsUp state to obtain lists of QNetworkAddressEntry objects then calling ip() on each of these.

static PySide6.QtNetwork.QNetworkInterface.allInterfaces()#
Return type:

Returns a listing of all the network interfaces found on the host machine. In case of failure it returns a list with zero elements.

PySide6.QtNetwork.QNetworkInterface.flags()#
Return type:

InterfaceFlags

Returns the flags associated with this network interface.

PySide6.QtNetwork.QNetworkInterface.hardwareAddress()#
Return type:

str

Returns the low-level hardware address for this interface. On Ethernet interfaces, this will be a MAC address in string representation, separated by colons.

Other interface types may have other types of hardware addresses. Implementations should not depend on this function returning a valid MAC address.

See also

type()

PySide6.QtNetwork.QNetworkInterface.humanReadableName()#
Return type:

str

Returns the human-readable name of this network interface on Windows, such as “Local Area Connection”, if the name could be determined. If it couldn’t, this function returns the same as name() . The human-readable name is a name that the user can modify in the Windows Control Panel, so it may change during the execution of the program.

On Unix, this function currently always returns the same as name() , since Unix systems don’t store a configuration for human-readable names.

PySide6.QtNetwork.QNetworkInterface.index()#
Return type:

int

Returns the interface system index, if known. This is an integer assigned by the operating system to identify this interface and it generally doesn’t change. It matches the scope ID field in IPv6 addresses.

If the index isn’t known, this function returns 0.

static PySide6.QtNetwork.QNetworkInterface.interfaceFromIndex(index)#
Parameters:

index – int

Return type:

PySide6.QtNetwork.QNetworkInterface

Returns a QNetworkInterface object for the interface whose internal ID is index. Network interfaces have a unique identifier called the “interface index” to distinguish it from other interfaces on the system. Often, this value is assigned progressively and interfaces being removed and then added again get a different value every time.

This index is also found in the IPv6 address’ scope ID field.

static PySide6.QtNetwork.QNetworkInterface.interfaceFromName(name)#
Parameters:

name – str

Return type:

PySide6.QtNetwork.QNetworkInterface

Returns a QNetworkInterface object for the interface named name. If no such interface exists, this function returns an invalid QNetworkInterface object.

The string name may be either an actual interface name (such as “eth0” or “en1”) or an interface index in string form (“1”, “2”, etc.).

See also

name() isValid()

static PySide6.QtNetwork.QNetworkInterface.interfaceIndexFromName(name)#
Parameters:

name – str

Return type:

int

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Returns the index of the interface whose name is name or 0 if there is no interface with that name. This function should produce the same result as the following code, but will probably execute faster.

QNetworkInterface.interfaceFromName(name).index()
static PySide6.QtNetwork.QNetworkInterface.interfaceNameFromIndex(index)#
Parameters:

index – int

Return type:

str

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Returns the name of the interface whose index is index or an empty string if there is no interface with that index. This function should produce the same result as the following code, but will probably execute faster.

QNetworkInterface.interfaceFromIndex(index).name()
PySide6.QtNetwork.QNetworkInterface.isValid()#
Return type:

bool

Returns true if this QNetworkInterface object contains valid information about a network interface.

PySide6.QtNetwork.QNetworkInterface.maximumTransmissionUnit()#
Return type:

int

Returns the maximum transmission unit on this interface, if known, or 0 otherwise.

The maximum transmission unit is the largest packet that may be sent on this interface without incurring link-level fragmentation. Applications may use this value to calculate the size of the payload that will fit an unfragmented UDP datagram. Remember to subtract the sizes of headers used in your communication over the interface, e.g. TCP (20 bytes) or UDP (12), IPv4 (20) or IPv6 (40, absent some form of header compression), when computing how big a payload you can transmit. Also note that the MTU along the full path (the Path MTU) to the destination may be smaller than the interface’s MTU.

See also

QUdpSocket

PySide6.QtNetwork.QNetworkInterface.name()#
Return type:

str

Returns the name of this network interface. On Unix systems, this is a string containing the type of the interface and optionally a sequence number, such as “eth0”, “lo” or “pcn0”. On Windows, it’s an internal ID that cannot be changed by the user.

PySide6.QtNetwork.QNetworkInterface.swap(other)#
Parameters:

otherPySide6.QtNetwork.QNetworkInterface

Swaps this network interface instance with other. This function is very fast and never fails.

PySide6.QtNetwork.QNetworkInterface.type()#
Return type:

InterfaceType

Returns the type of this interface, if it could be determined. If it could not be determined, this function returns Unknown .