public class Checkmacandip extends HttpServlet {
Public Checkmacandip () {
Super ();
}
public void Destroy () {
Super.destroy ();
}
public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
DoPost (Request,response);
}
public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
String IP = getremoteaddress (request);
SYSTEM.OUT.PRINTLN (IP);
SYSTEM.OUT.PRINTLN (getmacaddress (IP));
}
public void Init () throws Servletexception {
}
Public String getremoteaddress (HttpServletRequest request) {
String IP = request.getheader ("X-forwarded-for");
if (IP = null | | ip.length () = = 0 | | | ip.equalsignorecase ("unknown")) IP = Request.getheader ("Proxy-client-ip");
if (IP = null | | ip.length () = = 0 | | | ip.equalsignorecase ("unknown")) IP = Request.getheader ("Wl-proxy-client-ip");
if (IP = null | | ip.length () = = 0 | | | ip.equalsignorecase ("unknown")) IP = request.getremoteaddr ();
return IP;
}
public string getmacaddress (string IP) {
String str = "";
String macAddress = "";
try {
Process p = runtime.getruntime (). EXEC ("nbtstat-a" + IP);
InputStreamReader ir = new InputStreamReader (P.getinputstream ());
LineNumberReader input = new LineNumberReader (IR);
for (int i = 1; i < i++) {
str = Input.readline ();
if (str!= null) {
if (Str.indexof ("MAC address") > 1) {
macAddress = str.substring (Str.indexof ("MAC address") +, Str.length ());
Break
}
}
}
catch (IOException e) {
E.printstacktrace (System.out);
}
return macAddress;
}
}