Unsupported library that attempts to punch holes through NAT
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DiscoveryTestDemo.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * This file is part of JSTUN.
  3. *
  4. * Copyright (c) 2005 Thomas King <king@t-king.de> - All rights
  5. * reserved.
  6. *
  7. * This software is licensed under either the GNU Public License (GPL),
  8. * or the Apache 2.0 license. Copies of both license agreements are
  9. * included in this distribution.
  10. */
  11. package de.javawi.jstun.test.demo;
  12. import java.net.BindException;
  13. import java.net.InetAddress;
  14. import java.net.NetworkInterface;
  15. import java.util.Enumeration;
  16. import java.util.logging.FileHandler;
  17. import java.util.logging.Handler;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import java.util.logging.SimpleFormatter;
  21. import de.javawi.jstun.test.DiscoveryTest;
  22. public class DiscoveryTestDemo implements Runnable {
  23. InetAddress iaddress;
  24. public DiscoveryTestDemo(InetAddress iaddress) {
  25. this.iaddress = iaddress;
  26. }
  27. public void run() {
  28. try {
  29. DiscoveryTest test = new DiscoveryTest(iaddress, "jstun.javawi.de", 3478);
  30. //DiscoveryTest test = new DiscoveryTest(iaddress, "stun.sipgate.net", 10000);
  31. // iphone-stun.freenet.de:3478
  32. // larry.gloo.net:3478
  33. // stun.xten.net:3478
  34. // stun.sipgate.net:10000
  35. System.out.println(test.test());
  36. } catch (BindException be) {
  37. System.out.println(iaddress.toString() + ": " + be.getMessage());
  38. } catch (Exception e) {
  39. System.out.println(e.getMessage());
  40. e.printStackTrace();
  41. }
  42. }
  43. public static void main(String args[]) {
  44. try {
  45. Handler fh = new FileHandler("logging.txt");
  46. fh.setFormatter(new SimpleFormatter());
  47. Logger.getLogger("de.javawi.stun").addHandler(fh);
  48. Logger.getLogger("de.javawi.stun").setLevel(Level.ALL);
  49. Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
  50. while (ifaces.hasMoreElements()) {
  51. NetworkInterface iface = ifaces.nextElement();
  52. Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
  53. while (iaddresses.hasMoreElements()) {
  54. InetAddress iaddress = iaddresses.nextElement();
  55. if (Class.forName("java.net.Inet4Address").isInstance(iaddress)) {
  56. if ((!iaddress.isLoopbackAddress()) && (!iaddress.isLinkLocalAddress())) {
  57. Thread thread = new Thread(new DiscoveryTestDemo(iaddress));
  58. thread.start();
  59. }
  60. }
  61. }
  62. }
  63. } catch (Exception e) {
  64. System.out.println(e.getMessage());
  65. }
  66. }
  67. }