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