def test_upnp( self ): internal_client = HydrusNATPunch.GetLocalIP() internal_port = random.randint( 1000, 1500 ) external_port = random.randint( 1000, 1500 ) description_tcp = 'hydrus test tcp' description_udp = 'hydrus test udp' HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, 'TCP', description_tcp ) HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, 'UDP', description_udp ) mappings = HydrusNATPunch.GetUPnPMappings() mappings_without_lease_times = [ mapping[:-1] for mapping in mappings ] self.assertIn( ( description_tcp, internal_client, internal_port, external_port, 'TCP' ), mappings_without_lease_times ) self.assertIn( ( description_udp, internal_client, internal_port, external_port, 'UDP' ), mappings_without_lease_times ) HydrusNATPunch.RemoveUPnPMapping( external_port, 'TCP' ) HydrusNATPunch.RemoveUPnPMapping( external_port, 'UDP' ) mappings = HydrusNATPunch.GetUPnPMappings() mappings_without_lease_times = [ mapping[:-1] for mapping in mappings ] self.assertNotIn( ( description_tcp, internal_client, internal_port, external_port, 'TCP' ), mappings_without_lease_times ) self.assertNotIn( ( description_udp, internal_client, internal_port, external_port, 'UDP' ), mappings_without_lease_times )
def _Edit( self ): do_refresh = False selected_mappings = self._mappings_list_ctrl.GetData( only_selected = True ) for selected_mapping in selected_mappings: ( description, internal_ip, internal_port, external_port, protocol, duration ) = selected_mapping with ClientGUIDialogs.DialogInputUPnPMapping( self, external_port, protocol, internal_port, description, duration ) as dlg: if dlg.exec() == QW.QDialog.Accepted: ( external_port, protocol, internal_port, description, duration ) = dlg.GetInfo() HydrusNATPunch.RemoveUPnPMapping( external_port, protocol ) internal_client = HydrusNATPunch.GetLocalIP() HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, protocol, description, duration = duration ) do_refresh = True else: break if do_refresh: self._RefreshMappings()
def work_callable(): for selected_mapping in selected_mappings: (description, internal_ip, internal_port, external_port, protocol, duration) = selected_mapping HydrusNATPunch.RemoveUPnPMapping(external_port, protocol) return True
def work_callable(): if remove_old: HydrusNATPunch.RemoveUPnPMapping( old_external_port, old_protocol) if remove_existing: HydrusNATPunch.RemoveUPnPMapping( external_port, protocol) internal_client = HydrusNATPunch.GetLocalIP() HydrusNATPunch.AddUPnPMapping(internal_client, internal_port, external_port, protocol, description, duration=duration) return True
def _Remove( self ): do_refresh = False selected_mappings = self._mappings_list_ctrl.GetData( only_selected = True ) for selected_mapping in selected_mappings: ( description, internal_ip, internal_port, external_port, protocol, duration ) = selected_mapping HydrusNATPunch.RemoveUPnPMapping( external_port, protocol ) do_refresh = True if do_refresh: self._RefreshMappings()