offbynull / portmapper

Java library that maps ports on NAT-enabled routers (supported protocols: UPnP-IGD/NAT-PMP/PCP).
Apache License 2.0
88 stars 17 forks source link

No mappers found #24

Closed delthas closed 8 years ago

delthas commented 8 years ago

I've tried to run the example you give in the project readme but no mappers are returned by PortMapperFactory.discover. In fact a bunch of exceptions are raised during PortMapperFactory.discover.

Here's the program I ran:

public static void main(String... strings) throws Exception {
    System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
    Gateway network = NetworkGateway.create();
    Gateway process = ProcessGateway.create();
    Bus networkBus = network.getBus();
    Bus processBus = process.getBus();
    List<PortMapper> mappers = PortMapperFactory.discover(networkBus, processBus);
    System.out.println("Number of mappers found: " + mappers.size());
    // Stop gateways
    networkBus.send(new KillNetworkRequest());
    processBus.send(new KillProcessRequest()); // can kill this after discovery
}

My computer local IP address is 192.168.0.11, and my router local IP address is 192.168.0.254. I'm running Windows 10 (64 bits). Here are the logs: log

offbynull commented 8 years ago

I think I found the problem. Going to add a test case to verify.

offbynull commented 8 years ago

Can you test this change when you have a moment to spare? Steps are as follows...

  1. checkout source code
  2. mvn clean install
  3. change version in your project from 2.0.0 to 2.0.1-SNAPSHOT

Please let me know the results.

delthas commented 8 years ago

I tested the change on my machine. It worked, the program found one mapper, and I checked on my router that the port forwarding was working. However there are still tons of exceptions (maybe that's normal?) so here are the (new) logs in case you want to take a look at them: mynewlogs I also run the same program on a friend's computer (not on the same local network). I'm not sure whether his router has Upnp IGD enabled or not, but the program hasn't been able to find any port mapper and has thrown a bunch of exceptions too, so here's the logs: friendlogs

offbynull commented 8 years ago

The exceptions you see in your log are expected. Java throws them when it tries to access a restricted/bad IP address. I need to figure out a way to prevent this from showing errors in the log.

As for your friend's log, the only device responding to the UPnP probing is a Samsung TV...

  <friendlyName>[TV]Samsung LED55</friendlyName>
  <manufacturer>Samsung Electronics</manufacturer>
  <manufacturerURL>http://www.samsung.com/sec</manufacturerURL>
  <modelDescription>Samsung TV NS</modelDescription>

Looking at the TV's UPnP service descriptions, it doesn't have port forwarding functionality.

What type of router is your friend using? does it support port forwarding via any of the 3 protocols? does port forwarding need to be enabled on his router?

delthas commented 8 years ago

Okay, well in fact I wasn't sure whether his router had UPnP enabled, so I just wanted to make sure all the exceptions were "normal". Someone probably completely disabled UPnP on my friend's router, so that's why it's not showing in the mappers list I guess. Thanks. Commit 3c865aa did fix the issue then.

offbynull commented 8 years ago

Thank you for the bug report and helping out with debugging/verification. I'll deploy an update to maven central this weekend.

I'll close this ticket once the deploy is complete.

offbynull commented 8 years ago

I've just performed a deploy. If all goes well, 2.0.1 should appear on central soon.

Closing ticket.