src/eric7/EricNetwork/EricNetworkUtilities.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 9158
47c32c123843
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Package implementing some special network related objects and functions.
8 """
9
10 from PyQt6.QtNetwork import QAbstractSocket, QHostAddress
11
12
13 def isValidAddress(address):
14 """
15 Public function to check, if the given address is valid.
16
17 @param address IPv4 or IPv6 address string
18 @type str
19 @return flag indicating validity
20 @rtype bool
21 """
22 h = QHostAddress(address)
23 return not h.isNull()
24
25
26 def isValidIPv4Address(address):
27 """
28 Public function to check, if the given address is a valid IPv4 address.
29
30 @param address IPv4 address string
31 @type str
32 @return flag indicating validity
33 @rtype bool
34 """
35 h = QHostAddress(address)
36 return (
37 not h.isNull() and
38 h.protocol() == QAbstractSocket.NetworkLayerProtocol.IPv4Protocol
39 )
40
41
42 def isValidIPv6Address(address):
43 """
44 Public function to check, if the given address is a valid IPv6 address.
45
46 @param address IPv6 address string
47 @type str
48 @return flag indicating validity
49 @rtype bool
50 """
51 h = QHostAddress(address)
52 return (
53 not h.isNull() and
54 h.protocol() == QAbstractSocket.NetworkLayerProtocol.IPv6Protocol
55 )

eric ide

mercurial