1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/guce", "root", "");
PreparedStatement pst = conn.prepareStatement("Select * from adress where mac=?");
pst.setString(1, sb.toString());
ResultSet rs = pst.executeQuery();
if (rs.next()) {
getServletContext().getRequestDispatcher("/login_login.jsp").forward(request, response);
conn.close();
} else {
getServletContext().getRequestDispatcher("/controlle.jsp").forward(request, response);
conn.close();
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
} |
Partager