This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » ASP » Convert IP address to full 15 character IP address
Reply

Convert IP address to full 15 character IP address

Somjad P
Member



Since: 22 Feb 2010
Posts: 7
Posted 02 Jul 2010 16:13:21

Greetings,

Is there a way to convert any ip that i request from the server example = Request.ServerVariables("REMOTE_ADDR"
and have it change to the full 15 character ip?

Example 41.41.41.1 to 041.041.041.001

Thanks!

Greetings,

Is there a way to convert any ip that i request from the server example = Request.ServerVariables("REMOTE_ADDR"
and have it change to the full 15 character ip?

Example 41.41.41.1 to 041.041.041.001

Thanks!
Patrick Woldberg
Official Representative



Since: 11 Feb 2003
Posts: 1,894
Replied 05 Jul 2010 10:54:56
I hope I didn't make a mistake, here is the code:

<% 
Dim ip, parts, i

ip = Request.ServerVariables("REMOTE_ADDR")
parts = Split(ip, ".")

For i = 0 To UBound(parts)
  parts[i] = PadDigids(parts[i], 3)
Next

ip = Join(parts, ".")

Function PadDigits(n, totalDigits) 
  PadDigits = Right(String(totalDigits, "0") & n, totalDigits) 
End Function 
%>


What it does is split the string with the dot as delimiter, the parts are then the 4 numbers. In a loop we go through the number and add the extra zeros in front, the function PadDigits does this. Then we join the parts again to a string. Thats all

Reply to this topic

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency