Advertisement
JewishCat

Untitled

Feb 4th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.64 KB | None | 0 0
  1. package net;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.net.InetAddress;
  9. import java.net.NetworkInterface;
  10. import java.net.SocketException;
  11. import java.net.UnknownHostException;
  12. import java.util.Enumeration;
  13. import java.util.concurrent.atomic.AtomicLong;
  14. import net.lang.Hex;
  15.  
  16.  
  17. public final class y {
  18.  
  19.     private static AtomicLong a = new AtomicLong(Long.MIN_VALUE);
  20.  
  21.     private static String b = null;
  22.  
  23.     private static long c = 0x8000000000000000L;
  24.  
  25.     static {
  26.  
  27.         try {
  28.             Class.forName("java.net.InterfaceAddress");
  29.             b = y.class.newInstance().toString();
  30.         }
  31.         catch (ExceptionInInitializerError err) {
  32.  
  33.         }
  34.         catch (ClassNotFoundException ex) {
  35.  
  36.         }
  37.         catch (LinkageError err) {
  38.  
  39.         }
  40.         catch (IllegalAccessException ex) {
  41.  
  42.         }
  43.         catch (InstantiationException ex) {
  44.  
  45.         }
  46.         catch (SecurityException ex) {
  47.  
  48.         }
  49.  
  50.         if (b == null) {
  51.  
  52.             Process p = null;
  53.             BufferedReader in = null;
  54.  
  55.             try {
  56.                 String osname = System.getProperty("os.name", ""), osver = System.getProperty("os.version", "");
  57.  
  58.                 if (osname.startsWith("Windows")) {
  59.                     p = Runtime.getRuntime().exec(
  60.                     new String[] { "ipconfig", "/all" }, null);
  61.                 }
  62.  
  63.                 else if (osname.startsWith("Solaris")
  64.                         || osname.startsWith("SunOS")) {
  65.                     if (osver.startsWith("5.11")) {
  66.                         p = Runtime.getRuntime().exec(
  67.                         new String[] { "dladm", "show-phys", "-m" }, null);
  68.                     }
  69.                     else {
  70.                         String hostName = getFirstLineOfCommand("uname", "-n");
  71.                         if (hostName != null) {
  72.                             p = Runtime.getRuntime().exec(
  73.                                     new String[] { "/usr/sbin/arp", hostName },
  74.                                     null);
  75.                         }
  76.                     }
  77.                 }
  78.                 else if (new File("/usr/sbin/lanscan").exists()) {
  79.                     p = Runtime.getRuntime().exec(
  80.                             new String[] { "/usr/sbin/lanscan" }, null);
  81.                 }
  82.                 else if (new File("/sbin/ifconfig").exists()) {
  83.                     p = Runtime.getRuntime().exec(
  84.                             new String[] { "/sbin/ifconfig", "-a" }, null);
  85.                 }
  86.  
  87.                 if (p != null) {
  88.                     in = new BufferedReader(new InputStreamReader(
  89.                             p.getInputStream()), 128);
  90.                     String l = null;
  91.                     while ((l = in.readLine()) != null) {
  92.                         b = x.parse(l);
  93.                         if (b != null
  94.                                 && Hex.parseShort(b) != 0xff) {
  95.                             break;
  96.                         }
  97.                     }
  98.                 }
  99.  
  100.             }
  101.             catch (SecurityException ex) {
  102.  
  103.             }
  104.             catch (IOException ex) {
  105.  
  106.             }
  107.             finally {
  108.                 if (p != null) {
  109.                     close(in, p.getErrorStream(), p.getOutputStream());
  110.                     p.destroy();
  111.                 }
  112.             }
  113.  
  114.         }
  115.  
  116.         if (b != null) {
  117.             c |= Hex.parseLong(b);
  118.         }
  119.         else {
  120.             try {
  121.                 byte[] local = InetAddress.getLocalHost().getAddress();
  122.                 c |= (local[0] << 24) & 0xFF000000L;
  123.                 c |= (local[1] << 16) & 0xFF0000;
  124.                 c |= (local[2] << 8) & 0xFF00;
  125.                 c |= local[3] & 0xFF;
  126.             }
  127.             catch (UnknownHostException ex) {
  128.                 c |= (long) (Math.random() * 0x7FFFFFFF);
  129.             }
  130.         }
  131.  
  132.         c |= (long) (Math.random() * 0x3FFF) << 48;
  133.  
  134.     }
  135.  
  136.     public static long getClockSeqAndNode() {
  137.         return c;
  138.     }
  139.  
  140.     public static long newTime() {
  141.         return createTime(System.currentTimeMillis());
  142.     }
  143.  
  144.     public static long createTime(long currentTimeMillis) {
  145.  
  146.         long time;
  147.  
  148.  
  149.         long timeMillis = (currentTimeMillis * 10000) + 0x01B21DD213814000L;
  150.  
  151.         while (true) {
  152.             long current = a.get();
  153.             if (timeMillis > current) {
  154.                 if (a.compareAndSet(current, timeMillis)) {
  155.                     break;
  156.                 }
  157.             } else {
  158.                 if (a.compareAndSet(current, current + 1)) {
  159.                     timeMillis = current + 1;
  160.                     break;
  161.                 }
  162.             }
  163.         }
  164.  
  165.  
  166.         time = timeMillis << 32;
  167.  
  168.         time |= (timeMillis & 0xFFFF00000000L) >> 16;
  169.  
  170.         time |= 0x1000 | ((timeMillis >> 48) & 0x0FFF); // version 1
  171.  
  172.         return time;
  173.  
  174.     }
  175.  
  176.     public static String e() {
  177.         return b;
  178.     }
  179.  
  180.     static String getFirstLineOfCommand(String... commands) throws IOException {
  181.  
  182.         Process p = null;
  183.         BufferedReader reader = null;
  184.  
  185.         try {
  186.             p = Runtime.getRuntime().exec(commands);
  187.             reader = new BufferedReader(new InputStreamReader(
  188.                     p.getInputStream()), 128);
  189.  
  190.             return reader.readLine();
  191.         }
  192.         finally {
  193.             if (p != null) {
  194.                 close(reader, p.getErrorStream(), p.getOutputStream());
  195.                 p.destroy();
  196.             }
  197.         }
  198.  
  199.     }
  200.  
  201.         @Override
  202.         public String toString() {
  203.             String out = null;
  204.             try {
  205.                 Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();
  206.                 if (ifs != null) {
  207.                     while (ifs.hasMoreElements()) {
  208.                         NetworkInterface iface = ifs.nextElement();
  209.                         byte[] hardware = iface.getHardwareAddress();
  210.                         if (hardware != null && hardware.length == 6
  211.                                 && hardware[1] != (byte) 0xff) {
  212.                             out = Hex.append(new StringBuilder(36), hardware).toString();
  213.                             break;
  214.                         }
  215.                     }
  216.                 }
  217.             }
  218.             catch (SocketException ex) {
  219.  
  220.             }
  221.             return out;
  222.         }
  223.  
  224.     //}
  225.     private static void close(BufferedReader in, InputStream errorStream, OutputStream outputStream) {
  226.         throw new UnsupportedOperationException("Not yet implemented");
  227.     }
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement