Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

iRule - create cookie and insert value of client FQDN

I am trying to create an iRule that will create a cookie on the client and insert the client FQDN and client IP address into the cookie. So far, the iRUle will insert the client IP address but I can't find how to insert the client FQDN. Any help would be appreciated. Thanks

when HTTP_RESPONSE {

Check if the cookie exists in request

if { not ( [HTTP::cookie exists "LBSRC"] ) } {

Change cookie's value

HTTP::cookie insert name "LBSRC" value [IP::client_addr] } }

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi,

try this:

when HTTP_REQUEST {

set hostname [HTTP::host]
set client_ip [IP::client_addr]
set nocookie 1


if { [HTTP::cookie exists LBSRC] } {        
set nocookie 0
}


}
when HTTP_RESPONSE {
if {$nocookie} {
  HTTP::cookie insert name LBSRC value "$hostname $client_ip"
}
}

Let me now if you need more details...

Regards

0
Comments on this Answer
Comment made 11-Jun-2018 by bedwards311 1

Thanks for the response. I tried your iRule. I am getting the FQDN of the server I am trying to reach but not the client's FQDN.

0
Comment made 11-Jun-2018 by youssef 3608

I don't realy understand, what do you want to reach?

did you check with your browser if the cookie is set (use chrome with Developer tools --> F12)

As you can noticed, in my irule i create an cookie LBSRC with this kind of value "fqdn ip" -> "myapp.domain.com 1.2.3.4" that's you waiting for?

0
Comment made 11-Jun-2018 by bedwards311 1

The cookie "LBSRC" is set with your iRule, however the fqdn value is of the server itself "myapp.domain.com". What I am looking for is the fqdn of the client computer "test-pc.slcc.edu" accessing the server "myapp.domain.com". I am collecting analytics on users that visit "myapp.domain.com" and need the domain or fqdn of the client. In this case I would be looking for "slcc.edu" for the client computer "test-pc.slcc.edu". thanks

0
Comment made 14-Jun-2018 by youssef 3608

So in this case you need to retrieve source IP utilisateur then retrieve the PTR in order to retrieve fqdn of user computer. For doing this you need DNS services in order to use it in irule. did you have this add-on? or GTM/DNS

regards

0
Comment made 19-Jun-2018 by bedwards311 1

Thanks for the response. I will test by adding the DNS module. Do you know the syntax for what is needed to retrieve the PTR?

0
Comment made 21-Jun-2018 by youssef 3608

Hi try this:

# Client IP
clientip "[IP::client_addr]" 

# Client PTR / FQDN
set fqdn [RESOLV::lookup @/Common/pool-dns -ptr $clientip]

log local0. "clientip: $clientip - fqdn: $fqdn"

Keep me in touch.

Regards

0