FIND_REAL_IP finds the real ip address and not the localhost address (127.0.0.1) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: find_real_ip finds the real ip address and not the localhost address (127.0.0.1) CALL: ip = find_real_ip(); VERSION: $Id: find_real_ip.html,v 1.1 2008/02/12 12:19:20 hewitson Exp $ HISTORY: 04-01-2008 Diepholz Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function output_ip_address = find_real_ip(varargin) 0002 % FIND_REAL_IP finds the real ip address and not the localhost address (127.0.0.1) 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: find_real_ip finds the real ip address and not the localhost 0007 % address (127.0.0.1) 0008 % 0009 % CALL: ip = find_real_ip(); 0010 % 0011 % VERSION: $Id: find_real_ip.html,v 1.1 2008/02/12 12:19:20 hewitson Exp $ 0012 % 0013 % HISTORY: 04-01-2008 Diepholz 0014 % Creation 0015 % 0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0017 0018 0019 output_ip_address = NaN; 0020 0021 import java.net.*; 0022 0023 interfaces = NetworkInterface.getNetworkInterfaces(); 0024 0025 while(interfaces.hasMoreElements()) 0026 0027 ni = interfaces.nextElement(); 0028 0029 if ni.isLoopback == 1, continue, end 0030 0031 ip_list = ni.getInterfaceAddresses().listIterator(); 0032 0033 while(ip_list.hasNext()) 0034 0035 ip = ip_list.next(); 0036 0037 ip_address = ip.getAddress; 0038 0039 if (~ip_address.isLoopbackAddress && ip_address.getHostAddress().indexOf(':') == -1) 0040 output_ip_address = ip_address.getHostAddress; 0041 disp(sprintf('IP Address [%s] loopback [%d] SiteLocal [%d]', char(ip_address.getHostAddress), ip_address.isLoopbackAddress(), ip_address.isSiteLocalAddress())) ; 0042 end 0043 0044 end 0045 end 0046