Results 1 to 2 of 2
  1. #1
    Darkbound is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default One row help with Locking Java to MAC Adress

    Hello guys, I'm new to this forum and new to Java as well, I have an easy question (easy for the advanced programmers I guess). This is a code that checks the current MAC address of the PC and compares it to the one that's given in the source, if both MAC addresses are equal the program will run, if not it will return an error.

    Where is my problem?

    I found a code that checks the current MAC address and defines it under the variable "mac", what I need to know is how to get mac1 = mac address defined by me, so the program can compare both addresses and if they are equal it will run if not it will return an error.

    I hope that you understood what I'm asking for. Thanks in advance :)

    Java Code:
     import java.net.NetworkInterface;  
     import java.net.SocketException;  
     import java.util.Collections;  
     import java.util.Enumeration;  
    import javax.swing.JOptionPane;
     public class novprimer {    
         public static void main (String args[]) throws SocketException    
         {    
            byte[] macAddress;    
            Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();    
            for (NetworkInterface netint : Collections.list(nets))
            {    
               macAddress = netint.getHardwareAddress();    
               StringBuilder mac = new StringBuilder();  
    
    
    
    
    
               
               //mac1 = 00 00 00 00 00     - how to????
    
    
    
    
               
               if (macAddress != null)
               {    
                  for (byte b : macAddress)
                  {    
                     mac.append(String.format("%1$02X ", b));    
                  }    
               }       
            
            if (mac == mac1)
            {
            	String fn = JOptionPane.showInputDialog("Enter a:");
        		String sn = JOptionPane.showInputDialog("Enter b:");
        		String tn = JOptionPane.showInputDialog("Enter c:");
        		
        		double a = Integer.parseInt(fn);
        		double b = Integer.parseInt(sn);
        		double c = Integer.parseInt(tn);
        		double D = Math.sqrt(b*b-4*a*c);
        		
        		
        		double xa = (-b-D) / 2*a;
        		double xb = (-b+D) / 2*a;
        		double xab = -b/2*a;
        		
        		
        		
        		if (D==0)
        		{
        			JOptionPane.showMessageDialog(null,"x1x2= " + xab , 
        					"title", JOptionPane.PLAIN_MESSAGE);
        		}
        		else
        		{
        			JOptionPane.showMessageDialog(null,"x1= "+xa+" x2= "+xb,
    "title", JOptionPane.PLAIN_MESSAGE);
        		}
            	
            }
            else
            {
            	JOptionPane.showMessageDialog(null,"Error! " +
    "This program is not for this PC! :)", "Error!", JOptionPane.PLAIN_MESSAGE);
            }
            
            } 
            
            }    
      }

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    6

    Default

    Use the String args[] parameter passed by the system to your main method when it runs. args is an array of the command line arguments you set when you run the application, for example: java novprimer "00 00 00 00 00". The MAC address will be passed to your main method as args[0]. If you don't use the double quotes around it, it will treat each pair of digits as a separate argument, so you'll get 5 Strings in args, each with 2 digits.

Similar Threads

  1. locking strategies
    By jicxicmic in forum JDBC
    Replies: 0
    Last Post: 09-03-2009, 11:36 PM
  2. Get Ip adress?
    By Godsent in forum Networking
    Replies: 2
    Last Post: 07-11-2009, 02:15 PM
  3. Row level locking........
    By jithan in forum New To Java
    Replies: 0
    Last Post: 09-02-2008, 07:09 AM
  4. row level locking
    By jithan in forum New To Java
    Replies: 1
    Last Post: 08-28-2008, 06:42 PM
  5. Locking window in java
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 07:21 AM

Posting Permissions

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