Forums

ASP

This topic is locked

Convert IP address to full 15 character IP address

Posted 02 Jul 2010 16:13:21
1
has voted
02 Jul 2010 16:13:21 Somjad P posted:
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!

Replies

Replied 05 Jul 2010 10:54:56
05 Jul 2010 10:54:56 Patrick Woldberg replied:
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