![JAR search and dependency download from the Maven repository](/logo.png)
org.kawanfw.sql.jdbc.util.JdbcUtil Maven / Gradle / Ivy
/*
* This file is part of AceQL.
* AceQL: Remote JDBC access over HTTP.
* Copyright (C) 2015, KawanSoft SAS
* (http://www.kawansoft.com). All rights reserved.
*
* AceQL is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* AceQL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Any modifications to this file must keep this entire header
* intact.
*/
package org.kawanfw.sql.jdbc.util;
import java.net.InetAddress;
import java.net.NetworkInterface;
/**
* @author Nicolas de Pomereu
*
*/
public class JdbcUtil {
protected JdbcUtil() {
}
/**
* Returns the computer MAC address in 5C-26-0A-88-4E-DA format.
*
* @return the name or "00" if the MAC address cannot be found
*/
public static String getMacAddress() {
String macAddress = null;
try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
if (network == null) {
macAddress = "00";
return macAddress;
}
byte[] mac = network.getHardwareAddress();
if (mac == null) {
macAddress = "00";
return macAddress;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i],
(i < mac.length - 1) ? "-" : ""));
}
macAddress = sb.toString();
return macAddress;
} catch (Exception e) {
macAddress = "00";
return macAddress;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy