001package com.khubla.pragmatach.plugin.adminapp; 002 003import java.net.InterfaceAddress; 004import java.net.NetworkInterface; 005import java.util.ArrayList; 006import java.util.Enumeration; 007import java.util.List; 008 009import com.khubla.pragmatach.framework.annotation.Controller; 010import com.khubla.pragmatach.framework.annotation.Route; 011import com.khubla.pragmatach.framework.annotation.View; 012import com.khubla.pragmatach.framework.api.PragmatachException; 013import com.khubla.pragmatach.framework.api.Response; 014 015/** 016 * @author tome 017 */ 018@Controller(name = "pragmatachShowNetworkController") 019@View(view = "pragmatach/admin/network.html") 020public class ShowNetworkController extends SecuredAdminController { 021 /** 022 * ips of this host 023 */ 024 private List<String> ips; 025 026 private List<String> findIPs() throws PragmatachException { 027 try { 028 final List<String> ret = new ArrayList<String>(); 029 final Enumeration<NetworkInterface> enumer = NetworkInterface.getNetworkInterfaces(); 030 if (null != enumer) { 031 while (enumer.hasMoreElements()) { 032 final NetworkInterface networkInterface = enumer.nextElement(); 033 for (final InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) { 034 if (false == interfaceAddress.getAddress().isLoopbackAddress()) { 035 final String ip = interfaceAddress.getAddress().getHostAddress(); 036 if (false == ip.contains(":")) { 037 ret.add(ip); 038 } 039 } 040 } 041 } 042 } 043 return ret; 044 } catch (final Exception e) { 045 throw new PragmatachException("Exception in findIPs", e); 046 } 047 } 048 049 public List<String> getIps() { 050 return ips; 051 } 052 053 @Override 054 @Route(uri = "/pragmatach/admin/network") 055 public Response render() throws PragmatachException { 056 ips = findIPs(); 057 return super.render(); 058 } 059 060 public void setIps(List<String> ips) { 061 this.ips = ips; 062 } 063}