{"id":21387196,"url":"https://github.com/sshtools/porter","last_synced_at":"2025-07-14T06:33:33.308Z","repository":{"id":185864330,"uuid":"674212886","full_name":"sshtools/porter","owner":"sshtools","description":"Tiny Java library that uses UPnP to map external WAN ports to internal LAN ports for both TCP and UDP on a supporting router.","archived":false,"fork":false,"pushed_at":"2024-01-27T00:01:07.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-16T12:23:26.514Z","etag":null,"topics":["java","library","port-mapping","upnp"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sshtools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-03T11:55:55.000Z","updated_at":"2025-01-12T13:14:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"5fb16ce2-9bf7-44fd-bb36-c5dc9304fefa","html_url":"https://github.com/sshtools/porter","commit_stats":null,"previous_names":["sshtools/porter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sshtools/porter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshtools","download_url":"https://codeload.github.com/sshtools/porter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fporter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265252838,"owners_count":23735086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","library","port-mapping","upnp"],"created_at":"2024-11-22T12:12:06.360Z","updated_at":"2025-07-14T06:33:33.257Z","avatar_url":"https://github.com/sshtools.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# porter\nTiny Java library that uses UPnP to map external WAN ports to internal LAN ports for both TCP and UDP on a supporting router.\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.sshtools/porter/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.sshtools/porter)\n[![javadoc](https://javadoc.io/badge2/com.sshtools/porter/javadoc.svg)](https://javadoc.io/doc/com.sshtools/porter)\n![JPMS](https://img.shields.io/badge/JPMS-com.sshtools.porter-purple)\n\n## Features\n\n * Discover UPnP routers on the network.\n * Discover external IP address.\n * Map external TCP and UDP ports to internal ones.\n * Automatically unmap on JVM shutdown.\n * Requires Java 11 or above.\n * Zero runtime dependencies.\n * Graal Native Image compatible.\n\n## Installation\n\nAvailable on Maven Central, so just add the following dependency to your project's `pom.xml`.\nAdjust for other build systems.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.sshtools\u003c/groupId\u003e\n    \u003cartifactId\u003eporter\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.1\u003c/version\u003e\n\u003c/dependency\u003e \n```\n\n### JPMS\n\nIf you are using [JPMS](https://en.wikipedia.org/wiki/Java_Platform_Module_System), add `com.sshtools.porter` to your `module-info.java`.\n\n## Usage\n\nUsage is very simple. A port mapping can be achieved with a single line of code.\n\n```java\nUPnP.gateway().ifPresent(gw -\u003e gw.map(80, Protocol.TCP));\n```\n\nOr to map different ports.\n\n```java\ngw.map(8080, 80, Protocol.TCP);\n```\n\nOr to unmap.\n\n```java\ngw.unmap(80, Protocol.TCP);\n```\n\nOr to test if mapped.\n\n```java\nvar mapped = gw.mapped(80, Protocol.TCP);\nif(mapped) {\n    System.out.println(\"Mapped!\");\n}\nelse {\n    System.out.println(\"Not Mapped!\");\n}\n```\n\nFor more control over the discovery process, instead of usage, `UPnP.gateway()`, use `DiscoveryBuilder`.\nYou can use this to configure, monitor discovery, list all gateways and more.\n\n```java\ntry(var discovery = new UPnP.DiscoveryBuilder().\n    withoutShutdownHooks().\n    onGateway(gw -\u003e {\n        System.out.format(\"Gateway found %s%n\", gw.ip());\n    }).\n    build()) {\n    \n    /* Not strictly needed, here from demonstrations purposes */\n    discovery.awaitCompletion();\n    \n    /* gateways() will wait till complete */\n    var count = discovery.gateways().size();\n    System.out.format(\"Found %d gateways%n\", count);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshtools%2Fporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshtools%2Fporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshtools%2Fporter/lists"}