diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/network/DNSLookup.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/network/DNSLookup.java')
| -rw-r--r-- | NET/worlds/network/DNSLookup.java | 244 |
1 files changed, 244 insertions, 0 deletions
diff --git a/NET/worlds/network/DNSLookup.java b/NET/worlds/network/DNSLookup.java new file mode 100644 index 0000000..026b641 --- /dev/null +++ b/NET/worlds/network/DNSLookup.java @@ -0,0 +1,244 @@ +/* */ package NET.worlds.network; +/* */ +/* */ import java.net.MalformedURLException; +/* */ import java.net.URL; +/* */ import java.net.UnknownHostException; +/* */ import java.util.Hashtable; +/* */ import java.util.StringTokenizer; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class DNSLookup +/* */ implements Runnable +/* */ { +/* */ private static final int defaultTimeout = 30; +/* 69 */ private static Hashtable<String, String[]> cache = new Hashtable(); +/* */ +/* */ private String hostName; +/* */ +/* */ private String[] dottedNames; +/* */ +/* */ private int timeout; +/* */ +/* */ +/* */ public static URL lookup(URL url) +/* */ throws MalformedURLException, UnknownHostException +/* */ { +/* 81 */ return lookup(url, 30); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public static URL lookupAll(URL url) +/* */ throws MalformedURLException, UnknownHostException +/* */ { +/* 90 */ return lookupAll(url, 30); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public static URL lookup(URL url, int timeout) +/* */ throws MalformedURLException, UnknownHostException +/* */ { +/* 99 */ String hostName = url.getHost(); +/* 100 */ if (hostName == null) { +/* 101 */ return url; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 113 */ return new URL(url.getProtocol(), hostName, url.getPort(), url +/* 114 */ .getFile()); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static URL lookupAll(URL url, int timeout) +/* */ throws MalformedURLException, UnknownHostException +/* */ { +/* 124 */ String hostName = url.getHost(); +/* 125 */ if (hostName == null) { +/* 126 */ return url; +/* */ } +/* 128 */ String[] addresses = lookupAll(hostName, timeout); +/* 129 */ String hosts = ""; +/* 130 */ for (int i = 0; i < addresses.length; i++) { +/* 131 */ if (i != 0) +/* 132 */ hosts = hosts + ";"; +/* 133 */ hosts = hosts + addresses[i]; +/* */ } +/* 135 */ return new URL(url.getProtocol(), hosts, url.getPort(), url.getFile()); +/* */ } +/* */ +/* */ public static String lookup(String hostName) throws UnknownHostException +/* */ { +/* 140 */ return lookup(hostName, 30); +/* */ } +/* */ +/* */ public static String lookup(String hostName, int timeout) +/* */ throws UnknownHostException +/* */ { +/* 146 */ if (isDotted(hostName)) +/* 147 */ return hostName; +/* 148 */ return lookupAllCommon(hostName, timeout)[0]; +/* */ } +/* */ +/* */ public static String[] lookupAll(String hostName) +/* */ throws UnknownHostException +/* */ { +/* 154 */ return lookupAll(hostName, 30); +/* */ } +/* */ +/* */ public static String[] lookupAll(String hostName, int timeout) +/* */ throws UnknownHostException +/* */ { +/* 160 */ if (isDotted(hostName)) { +/* 161 */ String[] names = new String[1]; +/* 162 */ names[0] = hostName; +/* 163 */ return names; +/* */ } +/* 165 */ return lookupAllCommon(hostName, timeout); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private static String[] lookupAllCommon(String hostName, int timeout) +/* */ throws UnknownHostException +/* */ { +/* 174 */ String[] dotted = (String[])cache.get(hostName); +/* 175 */ if (dotted == null) { +/* 176 */ dotted = new DNSLookup(hostName, timeout).getDottedNames(); +/* 177 */ if (dotted == null) +/* 178 */ throw new UnknownHostException(hostName); +/* 179 */ cache.put(hostName, dotted); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* 185 */ return dotted; +/* */ } +/* */ +/* */ private DNSLookup(String hostName, int timeout) { +/* 189 */ this.hostName = hostName; +/* 190 */ this.timeout = timeout; +/* 191 */ if (timeout != 0) { +/* 192 */ Thread t = new Thread(this); +/* 193 */ t.setDaemon(true); +/* 194 */ t.start(); +/* */ } else { +/* 196 */ run(); +/* */ } +/* */ } +/* */ +/* */ public void run() { +/* 201 */ this.dottedNames = gethostbyname(this.hostName); +/* 202 */ if (this.timeout != 0) { +/* 203 */ synchronized (this) { +/* 204 */ notify(); +/* */ } +/* */ } +/* */ } +/* */ +/* */ private synchronized String[] getDottedNames() { +/* 210 */ if ((this.dottedNames == null) && (this.timeout != 0)) { +/* */ try { +/* 212 */ wait(this.timeout * 1000); +/* */ } +/* */ catch (InterruptedException localInterruptedException) {} +/* */ } +/* 216 */ return this.dottedNames; +/* */ } +/* */ +/* */ +/* */ private static boolean isDotted(String name) +/* */ { +/* 222 */ StringTokenizer tok = new StringTokenizer(name, "."); +/* 223 */ if (tok.countTokens() != 4) +/* 224 */ return false; +/* 225 */ for (int i = 0; i < 4; i++) { +/* */ try { +/* 227 */ int val = Integer.parseInt(tok.nextToken()); +/* 228 */ if ((val < 0) || (val > 255)) +/* 229 */ return false; +/* */ } catch (NumberFormatException nfe) { +/* 231 */ return false; +/* */ } +/* */ } +/* 234 */ return true; +/* */ } +/* */ +/* */ private static native String[] gethostbyname(String paramString); +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\DNSLookup.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |