def do_get_socket_info(self, s): if not s: return None info = {} try: info.update({ "proto": s.proto, "family": FAMILY_STR.get(s.family, int(s.family)), "type": PROTOCOL_STR.get(s.type, int(s.type)), }) except Exception: log("do_get_socket_info()", exc_info=True) if self.nodelay is not None: info["nodelay"] = self.nodelay try: info["timeout"] = int(1000 * (s.gettimeout() or 0)) except: pass try: if POSIX: fd = s.fileno() else: fd = 0 if fd: info["fileno"] = fd from xpra.platform.netdev_query import get_interface_info #ie: self.local = ("192.168.1.7", "14500") if self.local and len(self.local) == 2: from xpra.net.net_util import get_interface iface = get_interface(self.local[0]) #ie: iface = "eth0" if iface and iface != "lo": i = get_interface_info(fd, iface) if i: info["device"] = i except OSError as e: log("do_get_socket_info() error querying socket speed", exc_info=True) log.error("Error querying socket speed:") log.error(" %s", e) else: opts = { "SOCKET": get_socket_options(s, socket.SOL_SOCKET, SOCKET_OPTIONS), } if self.socktype in ("tcp", "udp", "ws", "wss", "ssl"): opts["IP"] = get_socket_options(s, socket.SOL_IP, IP_OPTIONS) if self.socktype in ("tcp", "ws", "wss", "ssl"): opts["TCP"] = get_socket_options(s, socket.IPPROTO_TCP, TCP_OPTIONS) #ipv6: IPV6_ADDR_PREFERENCES, IPV6_CHECKSUM, IPV6_DONTFRAG, IPV6_DSTOPTS, IPV6_HOPOPTS, # IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_NEXTHOP, IPV6_PATHMTU, # IPV6_PKTINFO, IPV6_PREFER_TEMPADDR, IPV6_RECVDSTOPTS, IPV6_RECVHOPLIMIT, IPV6_RECVHOPOPTS, # IPV6_RECVPATHMTU, IPV6_RECVPKTINFO, IPV6_RECVRTHDR, IPV6_RECVTCLASS, IPV6_RTHDR, # IPV6_RTHDRDSTOPTS, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_USE_MIN_MTU, IPV6_V6ONLY info["options"] = opts return info
def main(): # pragma: no cover from xpra.os_util import POSIX from xpra.util import print_nested_dict, csv from xpra.platform import program_context from xpra.platform.netdev_query import get_interface_info from xpra.log import enable_color, add_debug_category, enable_debug_for with program_context("Network-Info", "Network Info"): enable_color() verbose = "-v" in sys.argv or "--verbose" in sys.argv if verbose: enable_debug_for("network") add_debug_category("network") log.enable_debug() print("Network interfaces found:") netifaces = import_netifaces() for iface in get_interfaces(): if if_nametoindex: print("* %s (index=%s)" % (iface.ljust(20), if_nametoindex(iface))) else: print("* %s" % iface) addresses = netifaces.ifaddresses(iface) #@UndefinedVariable pylint: disable=no-member for addr, defs in addresses.items(): if addr in (socket.AF_INET, socket.AF_INET6): for d in defs: ip = d.get("addr") if ip: stype = { socket.AF_INET: "IPv4", socket.AF_INET6: "IPv6", }[addr] print(" * %s: %s" % (stype, ip)) if POSIX: from xpra.net.socket_util import create_tcp_socket try: sock = create_tcp_socket(ip, 0) sockfd = sock.fileno() info = get_interface_info(sockfd, iface) if info: print(" %s" % info) finally: sock.close() if not POSIX: info = get_interface_info(0, iface) if info: print(" %s" % info) from xpra.os_util import bytestostr def pver(v): if isinstance(v, (tuple, list)): s = "" lastx = None for x in v: if lastx is not None: #dot seperated numbers if isinstance(lastx, int): s += "." else: s += ", " s += bytestostr(x) lastx = x return s if isinstance(v, bytes): v = bytestostr(v) if isinstance(v, str) and v.startswith("v"): return v[1:] return str(v) print("Gateways found:") for gt, idefs in get_gateways().items(): print("* %s" % gt) #ie: "INET" for i, idef in enumerate(idefs): if isinstance(idef, (list, tuple)): print(" [%i] %s" % (i, csv(idef))) continue print("") print("Protocol Capabilities:") netcaps = get_network_caps() netif = {"": bool(netifaces)} if netifaces_version: netif["version"] = netifaces_version netcaps["netifaces"] = netif print_nested_dict(netcaps, vformat=pver) print("") print("Network Config:") print_nested_dict(get_net_config()) net_sys = get_net_sys_config() if net_sys: print("") print("Network System Config:") print_nested_dict(net_sys) print("") print("SSL:") print_nested_dict(get_ssl_info(True)) try: from xpra.net.crypto import crypto_backend_init, get_crypto_caps crypto_backend_init() ccaps = get_crypto_caps() if ccaps: print("") print("Crypto Capabilities:") print_nested_dict(ccaps) except Exception as e: print("No Crypto:") print(" %s" % e) return 0
def do_get_socket_info(self, s) -> dict: if not s: return None info = {} try: info.update({ "proto" : s.proto, "family" : FAMILY_STR.get(s.family, int(s.family)), "type" : PROTOCOL_STR.get(s.type, int(s.type)), "cork" : self.cork, }) except AttributeError: log("do_get_socket_info()", exc_info=True) if self.nodelay is not None: info["nodelay"] = self.nodelay try: info["timeout"] = int(1000*(s.gettimeout() or 0)) except socket.error: pass try: if POSIX: fd = s.fileno() else: fd = 0 if fd: info["fileno"] = fd #ie: self.local = ("192.168.1.7", "14500") log("do_get_socket_info(%s) fd=%s, local=%s", s, fd, self.local) if self.local and len(self.local)==2: from xpra.net.net_util import get_interface iface = get_interface(self.local[0]) #ie: iface = "eth0" device_info = {} if iface: device_info["name"] = iface if iface and iface!="lo": try: from xpra.platform.netdev_query import get_interface_info except ImportError as e: log("do_get_socket_info() no netdev_query: %s", e) else: device_info.update(get_interface_info(fd, iface)) if device_info: info["device"] = device_info except (OSError, ValueError) as e: log("do_get_socket_info() error querying socket speed", exc_info=True) log.error("Error querying socket speed:") log.error(" %s", e) else: opts = { "SOCKET" : get_socket_options(s, socket.SOL_SOCKET, SOCKET_OPTIONS), } if self.socktype_wrapped in IP_SOCKTYPES: opts["IP"] = get_socket_options(s, socket.SOL_IP, IP_OPTIONS) if self.socktype_wrapped in TCP_SOCKTYPES: opts["TCP"] = get_socket_options(s, socket.IPPROTO_TCP, TCP_OPTIONS) from xpra.platform.netdev_query import get_tcp_info opts["TCP_INFO"] = get_tcp_info(s) #ipv6: IPV6_ADDR_PREFERENCES, IPV6_CHECKSUM, IPV6_DONTFRAG, IPV6_DSTOPTS, IPV6_HOPOPTS, # IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_NEXTHOP, IPV6_PATHMTU, # IPV6_PKTINFO, IPV6_PREFER_TEMPADDR, IPV6_RECVDSTOPTS, IPV6_RECVHOPLIMIT, IPV6_RECVHOPOPTS, # IPV6_RECVPATHMTU, IPV6_RECVPKTINFO, IPV6_RECVRTHDR, IPV6_RECVTCLASS, IPV6_RTHDR, # IPV6_RTHDRDSTOPTS, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_USE_MIN_MTU, IPV6_V6ONLY info["options"] = opts return info