<div>The following code might return the correct IP by calling ip:list() from erl shell</div>
<div> </div>
<div> </div>
<div>
<p>-module(ip).<br>-export([list/0]).</p>
<p>list()-><br> IpAddress=inet:getiflist(),<br> case IpAddress of<br>  {ok,IpList}-><br>    format_ip(IpList,[]);<br>  _-><br>   io:fwrite("Error ~p in getting ip list\n",[IpAddress])<br> end.<br> <br>
format_ip(Iplist,FormatedList)-><br> case Iplist of<br>  []-><br>   FormatedList;<br>  _-><br>   Ip=hd(Iplist),<br>   ReversedIp=lists:reverse(string:tokens(Ip,".")),<br>   FormatedIP=check_ip(ReversedIp,""),
<br>   format_ip(tl(Iplist),FormatedList++[FormatedIP])<br> end.</p>
<p>check_ip(IpList,Return)-><br> case IpList of<br>  []-><br>   Return;<br>  _-><br>   IpPart=lists:reverse(hd(IpList)),<br>   case length(IpPart) of<br>    3-><br>     NewPart=integer_to_list(list_to_integer(IpPart)),
<br>     case Return of<br>      ""-><br>       check_ip(tl(IpList),Return++NewPart);<br>      _-><br>       check_ip(tl(IpList),Return++"."++NewPart)<br>     end;<br>    2-><br>     NewPart=integer_to_list(list_to_integer(IpPart++"0")),
<br>     case Return of<br>      ""-><br>       check_ip(tl(IpList),Return++NewPart);<br>      _-><br>       check_ip(tl(IpList),Return++"."++NewPart)<br>     end;<br>    1-><br>     NewPart=integer_to_list(list_to_integer(IpPart++"00")),
<br>     case Return of<br>      ""-><br>       check_ip(tl(IpList),Return++NewPart);<br>      _-><br>       check_ip(tl(IpList),Return++"."++NewPart)<br>     end;<br>    _-><br>     io:fwrite("Illegal IP length\n")
<br>   end<br> end.</p></div><br><br>
<div><span class="gmail_quote">On 10/3/06, <b class="gmail_sendername">Shelton Tang</b> <<a href="mailto:shelton.ms@gmail.com">shelton.ms@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">I have one NIC with the address {192,168,0,150} on my Vista machine.<br>If I call inet:getiflist(),  it returns
<br>["51.0.861.291","100.0.0.721"].<br><br>Anybody know how to convert it to a valid format?<br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">
erlang-questions@erlang.org</a><br><a href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br><br clear="all"><br>-- <br>with regards,
<br>S.Surindar