Parse IP Address

I am trying to get the third octet in the client IP Address that will designate the zone the client resides in. So far I havenā€™t been able to create an expression tag to perform that function.

toInt(split("192.193.194.195","\\.")[2,0])

returns

194

split() will create a dataset, with each row being equal to the values between the separator string. The \. is a regex, for a period. Finally, [2,0] is the row,column of the 3rd octet.

Thank you for the fast reply.

I copied and pasted:
toInt(split(ā€œsource text stringā€,"\.")[2,0])
into the expression of my expression tag and get an ā€œEvaluation Errorā€.

Did you replace the source text for an actual IP address?

You can wrap it in a try in case there is an invalid address, syntatically speaking

try(toInt(split("source text string","\\.")[2,0]),-1)

returns

-1

This

try(toInt(split("192.193.194.195","\\.")[2,0]),-1)

returns

194

To expand on Kyleā€™s solution, to use the clientā€™s IP address:

try(toInt(split({[System]Client/Network/IPAddress},'\\.')[2,0]),-1)

EDIT: Added ā€œtryā€ function

Iā€™m using the system variable
toInt(split({[System]Client/Network/IPAddress},"\.")[2,0])

This is inside an Expression Tag

Iā€™m running 7.7.1 rc2

Ah. Try putting it in a Client Tag.

EDIT: You'll really want to put it in a Client Tag anyway, because you want it to work just inside each client. Expression Tags are global in nature.

What Jordan said is correct. That tag is not available in the gateway, as it is unique to the client runtime.

:smiley:
Thank you, that did it!

I was testing on the wrong one, I had a client tag I was experimenting with as well but was attempting your suggestion with an expression tag.