[erlang-questions] Sometime it's the simple stuff...

Nick Gerakines nick@REDACTED
Mon May 5 09:40:22 CEST 2008


This is what I came up with. Keep in mind its late.

%% @spec url_from_ip(IpTuple) -> string().
%% where
%%       IpTuple = {integer(), integer(), integer(), integer()}
%% @doc Stringify a url out of an ip.
%% Use: url_from_ip({10, 0, 100, 1}).
url_from_ip(IpTuple) ->
    "http://" ++
    lists:foldl(fun(A, "") -> A; (A, Acc) -> Acc ++ "." ++ A end, "",
[integer_to_list(X)|| X <- tuple_to_list(IpTuple)])
    ++ "/".

*duck*

# Nick Gerakines

On Thu, May 1, 2008 at 6:56 AM, Dave Bryson <daveb@REDACTED> wrote:
> I need to take an IP address in the form of "[{10,0,1,100}]" and
>  create an http URL like this:  "http://10.0.1.100/".  I've tried using
>  io_lib:format and successfully generated a list.  But, the inets http
>  client  doesn't  like the format and complains of a malformed URL.
>
>  What's the easiest way to convert an IP to the String version?
>
>  Thanks!
>  Dave
>  _______________________________________________
>  erlang-questions mailing list
>  erlang-questions@REDACTED
>  http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list