#81916 - 2002-02-26 03:12 AM
IP Address trimming
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
How do we get the IP Address to appear properly when we see the following: quote:
__1.__2.__3.__4
?? We really want to see - quote:
1.2.3.4
{Edit 30-April-2003} Note: This requires KiX version 4.10 or better.
code:
$ipadr=join(split(@IPADDRESS0,' '),'')
Thanks Jens!!
OK, so I want to segregate the second octet from 1.2.3.4. That is, I want to find the users that are in the "2" subnet. Expanding the above code, we can do that..
code:
$2oct=split(join(split(@IPADDRESS0,' '),''),'.')[1]
{/Edit}
{Edit 22-April-2003} If you have KiX 4.x, you can do the following:
code:
$1st=LTRIM(split(@ipaddress0,'.')[0]) $2nd=LTRIM(split(@ipaddress0,'.')[1]) $3rd=LTRIM(split(@ipaddress0,'.')[2]) $4th=LTRIM(split(@ipaddress0,'.')[3]) $ipadr='$1ST.$2ND.$3RD.$4TH' ; #ip#
{/Edit}
With Pre-4.x versions, you can do the following:
code:
;************************************************************************************* ; Get the User's IP Address and trim appropriately ;************************************************************************************* ;LTRIM - TRIM THE LEADING SPACES FROM A STRING ;SUBSTR - RETURNS PART OF STRING: START POSITION, LENGTH $1st=LTRIM(SUBSTR(@ipaddress0,1,3));#ip# $2nd=LTRIM(SUBSTR(@ipaddress0,5,3));#ip# Get the IP# and assign it to $ipadr $3rd=LTRIM(SUBSTR(@ipaddress0,9,3));#ip# $4th=LTRIM(SUBSTR(@ipaddress0,13,3));#ip# $ipadr='$1ST.$2ND.$3RD.$4TH';#ip#
[ 01. May 2003, 16:22: Message edited by: kdyer ]
|
Top
|
|
|
|
#81917 - 2002-12-08 04:56 AM
Re: IP Address trimming
|
Les
KiX Master
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
Sometimes you may want to break up the IP address into the individual octets and then do some sort of compare. Remember that the IP is a string vartype and the above code example retains the string format.  It is not advisable to do '>=' or '<=' compares with strings as you may have unexpected results. Better to convert the strings to numeric with Val().
code:
$1st = VAL(SUBSTR(@IPAddress0,1,3)) $2nd = VAL(SUBSTR(@IPAddress0,5,3)) $3rd = VAL(SUBSTR(@IPAddress0,9,3)) $4th = VAL(SUBSTR(@IPAddress0,13,3))
If doing any subnet calculating that is more complex than a single octet compare, take a look at the various subnet UDFs that have been posted. See also, sealeopard's FAQs on the topic. This is the first in a series of three: Topic: TCP/IP Primer, Part I - IP Addresses
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
Top
|
|
|
|
Moderator: Jochen, Radimus, Glenn Barnas, Allen, Arend_, ShaneEP, Mart
|
0 registered
and 645 anonymous users online.
|
|
|