构建网络拓扑

发布于 2024-08-13 21:07:33 字数 205 浏览 6 评论 0原文

我们正在尝试开发网络中可用设备的拓扑图。

我有系统的详细信息,如 IP、设备名称。

我需要做的就是将它们填充到图表上并以图形方式显示,问题是我们需要在 JSP 中完成它。

是否还有另一种方法,例如使用 Flex 进行显示,我将传递 IP/设备名称并创建环境。顺便说一句,它不固定在多少个系统上,所以它必须是动态的。

有人可以帮忙吗?

We are trying to develop a Topology Map of available devices in a network.

I have the details of the system, like IP, Device Name.

All I need to do is to populate them on the graph and show it graphically, the problem is that we need to do it in JSP.

Is there another way, like show using Flex, where I would pass IP/Device Name and just create the environment. BTW its not fixed on how many systems, so its gotta be dynamic.

Can someone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦初启 2024-08-20 21:07:33

首先,这不一定是 JSP 问题。获取网络设备列表不是在 JSP 文件中完成,而是在真正的 Java 类中完成。 JSP只是一种视图技术。

回到实际问题,首先可以使用 java.net.NetworkInterface 用于此目的的 API。

首先创建一个Servlet,它在doGet()方法中获取NetworkInterfaceList,将其放入请求范围并将请求转发到一个 JSP。由于 NetworkInterface 类已经符合 Javabean 规范并具有几个有用的 getter 方法,因此我们不需要将其包装在另一个 Javabean 类中,只需重用它即可。

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        List<NetworkInterface> networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        request.setAttribute("networkInterfaces", networkInterfaces);
    } catch (SocketException e) {
        throw new ServletException("Cannot obtain networkinterfaces.", e);
    }
    request.getRequestDispatcher("/WEB-INF/networkinterfaces.jsp").forward(request, response);
}

将此 Servlet 映射到 web.xmlurl-pattern(例如 /networkinterfaces)上。该 servlet 可通过 http://example.com/context/networkinterfaces 访问。

现在创建一个 JSP 文件 networkinterfaces.jsp,将其放置在 WEB-INF 中,以防止 http://example.com/context/networkinterfaces 直接访问。 jsp(以便用户被迫使用servlet)。使用 JSTL (只需将 JAR 放入 /WEB-INF/lib 如果尚未完成) c:forEach 标记迭代 List 并通过 EL

<c:forEach items="${networkInterfaces}" var="networkInterface">
    Name: ${networkInterface.name}<br>
    Display name: ${networkInterface.displayName}<br>
    MTU: ${networkInterface.MTU}<br>
    <c:forEach items="${networkInterface.interfaceAddresses}" var="interfaceAddress" varStatus="loop">
        IP address #${loop.index + 1}: ${interfaceAddress.address}<br>
    </c:forEach>
    <hr>
</c:forEach>

应该是这样。

编辑使其“直观地呈现”,可以使用 Java 2D API 生成图像,也可以使用 HTML/CSS 根据 servlet 中收集的信息定位元素。

First of all, this isn't necessarily a JSP problem. Obtaining list of network devices isn't to be done in a JSP file, but in a real Java class. JSP is just a view technology.

Back to the actual problem, to start you can use the java.net.NetworkInterface API for this.

First create a Servlet which obtains a List of NetworkInterfaces in the doGet() method, puts it in the request scope and forwards the request to a JSP. As NetworkInterface class already conforms the Javabean spec with several useful getter methods, we don't need to wrap it in another Javabean class and can just reuse it.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        List<NetworkInterface> networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        request.setAttribute("networkInterfaces", networkInterfaces);
    } catch (SocketException e) {
        throw new ServletException("Cannot obtain networkinterfaces.", e);
    }
    request.getRequestDispatcher("/WEB-INF/networkinterfaces.jsp").forward(request, response);
}

Map this servlet in web.xml on an url-pattern of for example /networkinterfaces. This servlet would be accessible by http://example.com/context/networkinterfaces.

Now create a JSP file networkinterfaces.jsp which you place in WEB-INF to prevent from direct access by http://example.com/context/networkinterfaces.jsp (so that users are forced to use the servlet). Use the JSTL (just put JAR in /WEB-INF/lib if not done yet) c:forEach tag to iterate over the List and access the getters by EL.

<c:forEach items="${networkInterfaces}" var="networkInterface">
    Name: ${networkInterface.name}<br>
    Display name: ${networkInterface.displayName}<br>
    MTU: ${networkInterface.MTU}<br>
    <c:forEach items="${networkInterface.interfaceAddresses}" var="interfaceAddress" varStatus="loop">
        IP address #${loop.index + 1}: ${interfaceAddress.address}<br>
    </c:forEach>
    <hr>
</c:forEach>

That should be it.

Edit to have it "visually presented", either use Java 2D API to generate an image or use HTML/CSS to position the elements based on the information gathered in servlet.

晒暮凉 2024-08-20 21:07:33

如果您想要一个相当最新的选项(尽管速度非常慢),您可以启动一系列 Tracert 实例,获取输出并解析 IP 跳数?然后,您可以使用图形 API 使用结果来链接/添加树结构中的节点。

然而,这将是一个耗时的过程。我确信有更好的方法,但这可能会让您考虑选择。

If you wanted a reasonably up to date (albeit horribly slow) option you could launch a series of tracert instances, get the output and parse the IP hops? Then you could use the results to link/add nodes in a tree structure using a graphing API.

This would be a time consuming processes however. I'm sure theres a better way, but this might get you thinking of options.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文