我正在获取系统的 MAC 地址,为此我需要使用
public static void main(String args[])throws Exception {
但由于某些原因,我想将该代码移到有人按下某个按钮时。我可以复制代码,但我不能
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
至
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) throws Exception
它发出系统声音,线条似乎无法编辑,
我在代码中使用它Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
这是我的主要代码:
String[] macArray = new String[1000];
macArray[0] = "74 E5 43 23 F1 B4 ";
macArray[1] = "74 E5 43 24 5F 18 ";
int i=0;
String[] current = new String[1000];
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements())
{
NetworkInterface nif = interfaces.nextElement();
byte[] lBytes = nif.getHardwareAddress();
StringBuffer lStringBuffer = new StringBuffer();
if (lBytes != null)
{
for (byte b : lBytes)
{
lStringBuffer.append(String.format("%1$02X ", new Byte(b)));
}
}
current[i]=lStringBuffer.toString();
System.out.println(lStringBuffer);
i++;
//System.out.println(lStringBuffer)
}
for(; i<1000; i++){
current[i]= "" + 0;
}
int te=0;
for(int j=0; j<1000; j++){
for(int k=0; k<1000; k++){
if(current[j].equals(macArray[k])){
System.out.println("WOW!!!");
te=1;
}
}
//System.out.println(current[j]);
}
if(te!=1){
JOptionPane.showMessageDialog(null,"Error");
System.exit(0);
}