Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Servlets 在基于servlet的web应用程序中获取LAN客户端计算机名_Servlets_Client Side_Lan_Computer Name - Fatal编程技术网

Servlets 在基于servlet的web应用程序中获取LAN客户端计算机名

Servlets 在基于servlet的web应用程序中获取LAN客户端计算机名,servlets,client-side,lan,computer-name,Servlets,Client Side,Lan,Computer Name,我有一个SpringMVC应用程序,它在局域网中运行。在那里,客户机的IP地址不断变化。因此,我希望获取客户端计算机名称(它们的计算机名称是固定的),因为我希望在不创建登录的情况下获取客户端计算机的详细信息 可以获取客户端计算机的名称吗??如果可能的话怎么办?? 或者有没有其他方法可以获取用户的详细信息 编辑: 到目前为止我已经试过了 在HttpServlet中 public void doGet(HttpServletRequest request, HttpServletResponse r

我有一个SpringMVC应用程序,它在局域网中运行。在那里,客户机的IP地址不断变化。因此,我希望获取客户端计算机名称(它们的计算机名称是固定的),因为我希望在不创建登录的情况下获取客户端计算机的详细信息

可以获取客户端计算机的名称吗??如果可能的话怎么办?? 或者有没有其他方法可以获取用户的详细信息

编辑: 到目前为止我已经试过了

在HttpServlet中

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 
    String hostname = request.getRemoteUser(); //this gives null
    String hostname = request.getRemoteHost(); //This gives host machine name
}
编辑:回复@Eugeny Loy 在web.xml中

<init-param>
    <param-name>jcifs.smb.client.username</param-name>
    <param-value>username</param-value>

</init-param>
可以获取客户端计算机的名称吗

这里您可能指的是NetBIOS名称。如果是这样的话,您应该使用一些在java中实现NetBIOS/SMB/CIFS的库来实现这一点

如果可能的话怎么办

看一看。我不会给出确切的代码片段,但这是解决这个问题的方向

或者有没有其他方法可以获取用户的详细信息

据我所知,您需要的是一种识别主机的方法,而您不能依赖IP地址

如果是这样的话,另一种选择是使用MAC地址,但您可能无法使用纯java实现这一点,因为java通常处理的是较低级别的协议,因此它的可移植性可能较低。也许会有帮助

更新

我遇到过NetBIOS/SMB/CIFS堆栈,但我还没有在Java和JCIFS中使用过它。这就是为什么我不会给出解决问题的具体代码段,而是给出您应该关注的方向

查看课程文档。似乎就是你要找的。另外,还可以查看以了解如何使用它

可以获取客户端计算机的名称吗

这里您可能指的是NetBIOS名称。如果是这样的话,您应该使用一些在java中实现NetBIOS/SMB/CIFS的库来实现这一点

如果可能的话怎么办

看一看。我不会给出确切的代码片段,但这是解决这个问题的方向

或者有没有其他方法可以获取用户的详细信息

据我所知,您需要的是一种识别主机的方法,而您不能依赖IP地址

如果是这样的话,另一种选择是使用MAC地址,但您可能无法使用纯java实现这一点,因为java通常处理的是较低级别的协议,因此它的可移植性可能较低。也许会有帮助

更新

我遇到过NetBIOS/SMB/CIFS堆栈,但我还没有在Java和JCIFS中使用过它。这就是为什么我不会给出解决问题的具体代码段,而是给出您应该关注的方向


查看课程文档。似乎就是你要找的。还可以查看以了解如何使用它。

我找到了获取客户机名称的方法

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 

    Logger.getLogger(this.getClass()).warning("Inside Confirm Servlet");  
    response.setContentType("text/html");

    String hostname = request.getRemoteHost(); // hostname
    System.out.println("hostname"+hostname);

    String computerName = null;
    String remoteAddress = request.getRemoteAddr();
    System.out.println("remoteAddress: " + remoteAddress);
    try {
        InetAddress inetAddress = InetAddress.getByName(remoteAddress);
        System.out.println("inetAddress: " + inetAddress);
        computerName = inetAddress.getHostName();

        System.out.println("computerName: " + computerName);


        if (computerName.equalsIgnoreCase("localhost")) {
            computerName = java.net.InetAddress.getLocalHost().getCanonicalHostName();
        } 
    } catch (UnknownHostException e) {

        }

    System.out.println("computerName: " + computerName);
}    

我找到了获取客户机名称的方法

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 

    Logger.getLogger(this.getClass()).warning("Inside Confirm Servlet");  
    response.setContentType("text/html");

    String hostname = request.getRemoteHost(); // hostname
    System.out.println("hostname"+hostname);

    String computerName = null;
    String remoteAddress = request.getRemoteAddr();
    System.out.println("remoteAddress: " + remoteAddress);
    try {
        InetAddress inetAddress = InetAddress.getByName(remoteAddress);
        System.out.println("inetAddress: " + inetAddress);
        computerName = inetAddress.getHostName();

        System.out.println("computerName: " + computerName);


        if (computerName.equalsIgnoreCase("localhost")) {
            computerName = java.net.InetAddress.getLocalHost().getCanonicalHostName();
        } 
    } catch (UnknownHostException e) {

        }

    System.out.println("computerName: " + computerName);
}    

你能给我们看看你到目前为止试过的代码吗?@JqueryLearner我编辑了我的问题..提问时也会显示代码。这会吸引更多用户回答。当你使用System.out.println()时,它会在服务器的控制台中打印出来machine@Neha你设法解决了这个问题吗?我的回答有用吗?需要澄清吗?你能给我们看一下你迄今为止试过的代码吗?@JqueryLearner我编辑了我的问题..提问时也会显示代码。这会吸引更多用户回答。当你使用System.out.println()时,它会在服务器的控制台中打印出来machine@Neha你设法解决了这个问题吗?我的回答有用吗?需要澄清吗?很抱歉耽搁了。我按照你说的那样试过了,我编辑了我的问题,包括了那个代码。我试着用我的机器作为服务器,另一台机器作为客户端。但是我得到了另一台机器的IP地址(不是用户名)。你能建议一种获得该用户名的方法吗?很抱歉耽搁了。我按照你说的做了尝试,并编辑了我的问题,包括了该代码。我试着用我的机器作为服务器,另一台机器作为客户端。但是我得到了另一台机器的IP地址(不是用户名)。你能建议一种获得该用户名的方法吗。