Thread: Need Some Testers For Class

Results 1 to 9 of 9
  1. #1 Need Some Testers For Class 
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    So I'm in need of some people to help me test this to make sure it fetches a serial number properly on all operating systems. This has been tested on windows 10 and mac os x and worked but I'm not sure about linux or windows 7/8. If you could simply run this class and let me know if it prints out the serial number that would be awesome.

    Code:
    package com;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.util.Scanner;
    
    import javax.swing.JOptionPane;
    
    public class Testing {
    
    	public static String serialNumber;
    	public static Platform platform;
    
    	/**
    	 * This Platform enum contains the different operative systems we are
    	 * expecting to deal with.
    	 */
    	private static enum Platform {
    		LINUX, MAC_OS_X, UNKOWN, WINDOWS;
    	}
    
    	/**
    	 * Internal function to determine the {@code Platform} type.
    	 *
    	 * @return the {@code Platform} this machine is running.
    	 */
    	private static Platform getPlatform() {
    		final String name = System.getProperty("os.name").toLowerCase();
    
    		if (name.contains("win")) {
    			return Platform.WINDOWS;
    		} else if (name.contains("mac")) {
    			return Platform.MAC_OS_X;
    		} else if (name.contains("linux")) {
    			return Platform.LINUX;
    		} else if (name.contains("unix")) {
    			return Platform.LINUX;
    		}
    
    		return Platform.UNKOWN;
    	}
    
    	public static String getSerialNumber() {
    
    		String sn = null;
    		OutputStream os = null;
    		InputStream is = null;
    		Runtime runtime = Runtime.getRuntime();
    		Process process = null;
    
    		switch (platform) {
    
    		case MAC_OS_X:
    
    			try {
    				process = runtime.exec(new String[] { "/usr/sbin/system_profiler", "SPHardwareDataType" });
    			} catch (IOException e) {
    				throw new RuntimeException(e);
    			}
    
    			os = process.getOutputStream();
    			is = process.getInputStream();
    
    			try {
    				os.close();
    			} catch (IOException e) {
    				throw new RuntimeException(e);
    			}
    
    			BufferedReader br = new BufferedReader(new InputStreamReader(is));
    			String line = null;
    			String marker = "Serial Number";
    			try {
    				while ((line = br.readLine()) != null) {
    					if (line.contains(marker)) {
    						sn = line.split(":")[1].trim();
    						break;
    					}
    				}
    			} catch (IOException e) {
    				throw new RuntimeException(e);
    			} finally {
    				try {
    					is.close();
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    
    			if (sn == null) {
    				throw new RuntimeException("Cannot find computer SN");
    			}
    
    			return sn;
    
    		case LINUX:
    			if (sn == null) {
    				sn = readDmidecode();
    			}
    			if (sn == null) {
    				sn = readLshal();
    			}
    			if (sn == null) {
    				throw new RuntimeException("Cannot find computer SN");
    			}
    			return sn;
    
    		case WINDOWS:
    			sn = "";
    
    			// SN of motherboard
    			try {
    				File file = File.createTempFile("realhowto", ".vbs");
    				file.deleteOnExit();
    				FileWriter fw = new java.io.FileWriter(file);
    
    				String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + "   (\"Select * from Win32_BaseBoard\") \n"
    						+ "For Each objItem in colItems \n" + "    Wscript.Echo objItem.SerialNumber \n" + "    exit for  ' do the first cpu only! \n" + "Next \n";
    
    				fw.write(vbs);
    				fw.close();
    				Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
    				BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    				String l;
    				while ((l = input.readLine()) != null) {
    					sn += l;
    				}
    				input.close();
    
    				// SN of C drive (shouldn't fail, hopefully...)
    				if (sn.isEmpty()) {
    					file = File.createTempFile("realhowto", ".vbs");
    					file.deleteOnExit();
    					fw = new java.io.FileWriter(file);
    
    					vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"C\")\n"
    							+ "Wscript.Echo objDrive.SerialNumber"; // see note
    					fw.write(vbs);
    					fw.close();
    					p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
    					input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    					while ((l = input.readLine()) != null) {
    						sn += l;
    					}
    					input.close();
    				}
    
    				// SN of bios
    				if (sn.isEmpty()) {
    					process = Runtime.getRuntime().exec(new String[] { "wmic", "bios", "get", "serialnumber" });
    
    					process.getOutputStream().close();
    					Scanner sc = new Scanner(process.getInputStream());
    					String property = sc.next();
    					String serial = sc.next();
    					sn = serial;
    					sc.close();
    				}
    
    				if (sn.isEmpty()) {
    					throw new RuntimeException("Unable to find SN");
    				}
    
    				return sn;
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    			return sn;
    		default:
    			return "empty_serial";
    		}
    
    	}
    
    	private static String readDmidecode() {
    
    		String line = null;
    		String marker = "Serial Number:";
    		BufferedReader br = null;
    		String serial = null;
    
    		try {
    			br = read("dmidecode -t system");
    			while ((line = br.readLine()) != null) {
    				if (line.indexOf(marker) != -1) {
    					serial = line.split(marker)[1].trim();
    					break;
    				}
    			}
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		} finally {
    			if (br != null) {
    				try {
    					br.close();
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    		}
    		return serial;
    	}
    
    	private static String readLshal() {
    
    		String line = null;
    		String marker = "system.hardware.serial =";
    		BufferedReader br = null;
    		String serial = null;
    
    		try {
    			br = read("lshal");
    			while ((line = br.readLine()) != null) {
    				if (line.indexOf(marker) != -1) {
    					serial = line.split(marker)[1].replaceAll("\\(string\\)|(\\')", "").trim();
    					break;
    				}
    			}
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		} finally {
    			if (br != null) {
    				try {
    					br.close();
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    		}
    		return serial;
    	}
    
    	private static BufferedReader read(String command) {
    
    		OutputStream os = null;
    		InputStream is = null;
    
    		Runtime runtime = Runtime.getRuntime();
    		Process process = null;
    		try {
    			process = runtime.exec(command.split(" "));
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		}
    
    		os = process.getOutputStream();
    		is = process.getInputStream();
    
    		try {
    			os.close();
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		}
    
    		return new BufferedReader(new InputStreamReader(is));
    	}
    
    	public static void main(String[] args) {
    		platform = getPlatform();
    		serialNumber = getSerialNumber();
    		final String name = System.getProperty("os.name").toLowerCase();
    		final String version = System.getProperty("os.version").toLowerCase();
    		JOptionPane.showMessageDialog(null, "OS: " + name + ", Version: " + version + ", Serial: " + serialNumber);
    
    	}
    
    }
    Reply With Quote  
     

  2. #2  
    Owner of Zamorak

    Zamorak's Avatar
    Join Date
    Apr 2012
    Posts
    588
    Thanks given
    297
    Thanks received
    132
    Rep Power
    518
    You're doing this to code a successful computer ban right?

    Also,

    It works and it printed out just fine on windows 8
    Reply With Quote  
     

  3. #3  
    Banned Need Some Testers For Class Market Banned

    -3clipse-'s Avatar
    Join Date
    May 2015
    Posts
    839
    Thanks given
    101
    Thanks received
    311
    Rep Power
    389
    Quote Originally Posted by Pro. View Post
    You're doing this to code a successful computer ban right?
    That's what I'm assuming as well, especially since MAC addresses can be changed easily.
    Reply With Quote  
     

  4. #4  
    Owner of Zamorak

    Zamorak's Avatar
    Join Date
    Apr 2012
    Posts
    588
    Thanks given
    297
    Thanks received
    132
    Rep Power
    518
    Quote Originally Posted by -3clipse- View Post
    That's what I'm assuming as well, especially since MAC addresses can be changed easily.
    Yea, it's actually a really good class.

    It works, I just printed out my serial number.
    Reply With Quote  
     

  5. #5  
    Banned Need Some Testers For Class Market Banned

    -3clipse-'s Avatar
    Join Date
    May 2015
    Posts
    839
    Thanks given
    101
    Thanks received
    311
    Rep Power
    389
    Quote Originally Posted by Arithium View Post
    So I'm in need of some people to help me test this to make sure it fetches a serial number properly on all operating systems. This has been tested on windows 10 and mac os x and worked but I'm not sure about linux or windows 7/8. If you could simply run this class and let me know if it prints out the serial number that would be awesome.

    Code:
    package com;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.util.Scanner;
    
    import javax.swing.JOptionPane;
    
    public class Testing {
    
    	public static String serialNumber;
    	public static Platform platform;
    
    	/**
    	 * This Platform enum contains the different operative systems we are
    	 * expecting to deal with.
    	 */
    	private static enum Platform {
    		LINUX, MAC_OS_X, UNKOWN, WINDOWS;
    	}
    
    	/**
    	 * Internal function to determine the {@code Platform} type.
    	 *
    	 * @return the {@code Platform} this machine is running.
    	 */
    	private static Platform getPlatform() {
    		final String name = System.getProperty("os.name").toLowerCase();
    
    		if (name.contains("win")) {
    			return Platform.WINDOWS;
    		} else if (name.contains("mac")) {
    			return Platform.MAC_OS_X;
    		} else if (name.contains("linux")) {
    			return Platform.LINUX;
    		} else if (name.contains("unix")) {
    			return Platform.LINUX;
    		}
    
    		return Platform.UNKOWN;
    	}
    
    	public static String getSerialNumber() {
    
    		String sn = null;
    		OutputStream os = null;
    		InputStream is = null;
    		Runtime runtime = Runtime.getRuntime();
    		Process process = null;
    
    		switch (platform) {
    
    		case MAC_OS_X:
    
    			try {
    				process = runtime.exec(new String[] { "/usr/sbin/system_profiler", "SPHardwareDataType" });
    			} catch (IOException e) {
    				throw new RuntimeException(e);
    			}
    
    			os = process.getOutputStream();
    			is = process.getInputStream();
    
    			try {
    				os.close();
    			} catch (IOException e) {
    				throw new RuntimeException(e);
    			}
    
    			BufferedReader br = new BufferedReader(new InputStreamReader(is));
    			String line = null;
    			String marker = "Serial Number";
    			try {
    				while ((line = br.readLine()) != null) {
    					if (line.contains(marker)) {
    						sn = line.split(":")[1].trim();
    						break;
    					}
    				}
    			} catch (IOException e) {
    				throw new RuntimeException(e);
    			} finally {
    				try {
    					is.close();
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    
    			if (sn == null) {
    				throw new RuntimeException("Cannot find computer SN");
    			}
    
    			return sn;
    
    		case LINUX:
    			if (sn == null) {
    				sn = readDmidecode();
    			}
    			if (sn == null) {
    				sn = readLshal();
    			}
    			if (sn == null) {
    				throw new RuntimeException("Cannot find computer SN");
    			}
    			return sn;
    
    		case WINDOWS:
    			sn = "";
    
    			// SN of motherboard
    			try {
    				File file = File.createTempFile("realhowto", ".vbs");
    				file.deleteOnExit();
    				FileWriter fw = new java.io.FileWriter(file);
    
    				String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + "   (\"Select * from Win32_BaseBoard\") \n"
    						+ "For Each objItem in colItems \n" + "    Wscript.Echo objItem.SerialNumber \n" + "    exit for  ' do the first cpu only! \n" + "Next \n";
    
    				fw.write(vbs);
    				fw.close();
    				Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
    				BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    				String l;
    				while ((l = input.readLine()) != null) {
    					sn += l;
    				}
    				input.close();
    
    				// SN of C drive (shouldn't fail, hopefully...)
    				if (sn.isEmpty()) {
    					file = File.createTempFile("realhowto", ".vbs");
    					file.deleteOnExit();
    					fw = new java.io.FileWriter(file);
    
    					vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"C\")\n"
    							+ "Wscript.Echo objDrive.SerialNumber"; // see note
    					fw.write(vbs);
    					fw.close();
    					p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
    					input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    					while ((l = input.readLine()) != null) {
    						sn += l;
    					}
    					input.close();
    				}
    
    				// SN of bios
    				if (sn.isEmpty()) {
    					process = Runtime.getRuntime().exec(new String[] { "wmic", "bios", "get", "serialnumber" });
    
    					process.getOutputStream().close();
    					Scanner sc = new Scanner(process.getInputStream());
    					String property = sc.next();
    					String serial = sc.next();
    					sn = serial;
    					sc.close();
    				}
    
    				if (sn.isEmpty()) {
    					throw new RuntimeException("Unable to find SN");
    				}
    
    				return sn;
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    			return sn;
    		default:
    			return "empty_serial";
    		}
    
    	}
    
    	private static String readDmidecode() {
    
    		String line = null;
    		String marker = "Serial Number:";
    		BufferedReader br = null;
    		String serial = null;
    
    		try {
    			br = read("dmidecode -t system");
    			while ((line = br.readLine()) != null) {
    				if (line.indexOf(marker) != -1) {
    					serial = line.split(marker)[1].trim();
    					break;
    				}
    			}
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		} finally {
    			if (br != null) {
    				try {
    					br.close();
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    		}
    		return serial;
    	}
    
    	private static String readLshal() {
    
    		String line = null;
    		String marker = "system.hardware.serial =";
    		BufferedReader br = null;
    		String serial = null;
    
    		try {
    			br = read("lshal");
    			while ((line = br.readLine()) != null) {
    				if (line.indexOf(marker) != -1) {
    					serial = line.split(marker)[1].replaceAll("\\(string\\)|(\\')", "").trim();
    					break;
    				}
    			}
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		} finally {
    			if (br != null) {
    				try {
    					br.close();
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    		}
    		return serial;
    	}
    
    	private static BufferedReader read(String command) {
    
    		OutputStream os = null;
    		InputStream is = null;
    
    		Runtime runtime = Runtime.getRuntime();
    		Process process = null;
    		try {
    			process = runtime.exec(command.split(" "));
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		}
    
    		os = process.getOutputStream();
    		is = process.getInputStream();
    
    		try {
    			os.close();
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		}
    
    		return new BufferedReader(new InputStreamReader(is));
    	}
    
    	public static void main(String[] args) {
    		platform = getPlatform();
    		serialNumber = getSerialNumber();
    		final String name = System.getProperty("os.name").toLowerCase();
    		final String version = System.getProperty("os.version").toLowerCase();
    		JOptionPane.showMessageDialog(null, "OS: " + name + ", Version: " + version + ", Serial: " + serialNumber);
    
    	}
    
    }
    Quote Originally Posted by Pro. View Post
    Yea, it's actually a really good class.

    It works, I just printed out my serial number.
    That's awesome, I'll probably use it then if OP doesn't mind.
    Reply With Quote  
     

  6. #6  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Anybody is welcome to use it, I just need to know it works on all operating systems. There is a bug with java that wont show windows 10 but still prints a serial number. I just need to make sure it works on everything so nobody has the same or an empty serial number.
    Reply With Quote  
     

  7. #7  
    anInt69

    Max _'s Avatar
    Join Date
    Feb 2012
    Age
    26
    Posts
    1,801
    Thanks given
    426
    Thanks received
    727
    Rep Power
    599
    Weird how people hated using computer SN's a few days ago

    Anyways yeah it works, gj.
    Reply With Quote  
     

  8. #8  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Quote Originally Posted by Max _ View Post
    Weird how people hated using computer SN's a few days ago

    Anyways yeah it works, gj.
    Its not how people hated using serial numbers, its that they hated how you did it.
    Reply With Quote  
     

  9. #9  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Bump, still need people wiwth other operating systems to test this.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 45
    Last Post: 10-18-2013, 10:24 PM
  2. Need some testers
    By T-Sex in forum Requests
    Replies: 0
    Last Post: 07-27-2010, 03:04 PM
  3. I need some suggestions for 'Perfect' PKing.
    By Ecstasy in forum RS2 Server
    Replies: 19
    Last Post: 03-03-2010, 10:58 AM
  4. Need Some Coderz FOR RS Server
    By Souder in forum Help
    Replies: 2
    Last Post: 06-18-2009, 01:45 AM
  5. need some stuff for emulous if you can
    By Georgeo in forum Requests
    Replies: 3
    Last Post: 03-25-2009, 06:06 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •