Subdomain Posts
None | 10 days ago
None | 10 days ago
None | 10 days ago
None | 10 days ago
JavaScript | 21 days ago
JavaScript | 25 days ago
JavaScript | 25 days ago
JavaScript | 25 days ago
None | 25 days ago
None | 33 days ago
Recent Posts
mIRC | 14 sec ago
None | 26 sec ago
None | 36 sec ago
VB.NET | 1 min ago
None | 1 min ago
None | 2 min ago
None | 2 min ago
PHP | 2 min ago
None | 2 min ago
None | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 23rd of Aug 2007 03:58:39 PM Download | Raw | Embed | Report
  1. // Returns the local machine's IP address as a dotted-quad string, by
  2. // sending myself a UDP packet with a unique string.  This function
  3. // UDP-broadcasts, otherwise the remote address of a received packet
  4. // is 127.0.0.1.
  5. function findMyIP() {
  6.   var sock = new java.net.DatagramSocket();
  7.   var sendSock = new java.net.DatagramSocket();
  8.   var secret = java.util.UUID.randomUUID().toString();
  9.   var place = new java.util.Hashtable(1); // thread-safe
  10.   // Receive UDP packet with secret in looping background thread.
  11.   spawn(function() {
  12.     var sb = new java.lang.StringBuffer();
  13.     sb.setLength(secret.length);
  14.     while(true) {
  15.       var p = new java.net.DatagramPacket(new java.lang.String(sb.toString()).getBytes(), secret.length);
  16.       sock.receive(p);
  17.       if (new java.lang.String(p.getData()) == secret) {
  18.         place.put("ip", p.getAddress().getHostAddress());
  19.         break;
  20.       }
  21.     }
  22.   });
  23.   // Send packets with secret until receiver thread puts IP into table.
  24.   while(true) {
  25.     var p = new java.net.DatagramPacket(new java.lang.String(secret).getBytes(),
  26.                                         secret.length,
  27.                                         java.net.InetAddress.getByName("255.255.255.255"),
  28.                                         sock.getLocalPort());
  29.     sendSock.send(p);
  30.     app.log("Waiting for my IP...");
  31.     java.lang.Thread.sleep(500);
  32.     var myIP = place.get("ip");
  33.     if (myIP != null) {
  34.       return myIP;
  35.     }
  36.   }
  37. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: