diff --git a/network.py b/network.py index 4d576a4..5fe7ed7 100644 --- a/network.py +++ b/network.py @@ -128,25 +128,33 @@ def get_MIB_TCP6TABLE_OWNER_PID_from_buffer(buffer): return _GENERATED_MIB_TCP6TABLE_OWNER_PID.from_buffer(buffer) -def get_tcp_ipv4_sockets(): - size = ctypes.c_uint(0) - try: - windows.winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET) - except windows.winproxy.IphlpapiError: - pass # Allow us to set size to the needed value - buffer = (ctypes.c_char * size.value)() - windows.winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET) - t = get_MIB_TCPTABLE_OWNER_PID_from_buffer(buffer) - return list(t.table) -def get_tcp_ipv6_sockets(): - size = ctypes.c_uint(0) - try: - windows.winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET6) - except windows.winproxy.IphlpapiError: - pass # Allow us to set size to the needed value - buffer = (ctypes.c_char * size.value)() - windows.winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET6) - t = get_MIB_TCP6TABLE_OWNER_PID_from_buffer(buffer) - return list(t.table) +class Network(object): + @staticmethod + def _get_tcp_ipv4_sockets(): + size = ctypes.c_uint(0) + try: + windows.winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET) + except windows.winproxy.IphlpapiError: + pass # Allow us to set size to the needed value + buffer = (ctypes.c_char * size.value)() + windows.winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET) + t = get_MIB_TCPTABLE_OWNER_PID_from_buffer(buffer) + return list(t.table) + + @staticmethod + def _get_tcp_ipv6_sockets(): + size = ctypes.c_uint(0) + try: + windows.winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET6) + except windows.winproxy.IphlpapiError: + pass # Allow us to set size to the needed value + buffer = (ctypes.c_char * size.value)() + windows.winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET6) + t = get_MIB_TCP6TABLE_OWNER_PID_from_buffer(buffer) + return list(t.table) + + + ipv4 = property(lambda self: self._get_tcp_ipv4_sockets()) + ipv6 = property(lambda self: self._get_tcp_ipv6_sockets()) diff --git a/remotectypes.py b/remotectypes.py index d79fe89..5af6db6 100644 --- a/remotectypes.py +++ b/remotectypes.py @@ -429,6 +429,8 @@ def transform_union_to_remote32bits(structcls): return RemoteUnion.from_fields(new_fields, base_cls=structcls) def transform_type_to_remote32bits(ftype): + if issubclass(ftype, RemoteStructureUnion): + return ftype if is_pointer_type(ftype): return MakePtr32(ftype._type_) if is_array_type(ftype):