Forum Discussion

pstavr's avatar
pstavr
Icon for Cirrus rankCirrus
Jan 05, 2022

F5 iRule to get data group address content values list

Hi

I am following this article for creating a data group on F5, populated from Azure IPv4 addresses.

https://devcentral.f5.com/s/articles/Dynamic-IP-update-of-Azure-IP-Ranges-and-store-them-in-data-groups

Eveyrthing works like a charm, and now I am trying to publish the content of that data group as an html web page, but I want the output to be formulated like:

13.8.1.0/24

13.9.0.0/16

18.5.0.0/16

etc.

So it has to be presented as a list with line breaks for each entry.

Right now I am using this iRule:

when HTTP_REQUEST {
   switch -glob [string tolower [HTTP::uri]] {
    "/azure.html" {
       # Retrieve the Azure datagroup contents, send it in a HTTP 200 response
	   HTTP::respond 200 content [class get azure_ipv4_dg] "Content-Type" "text/html"
    }
default {
            ## requested something else
            HTTP::respond 404 content "Oops! You've asked for something we don't have."
        }   
   }
}

The output though comes like this:

{102.133.0.0/18 {}} {102.133.112.0/28 {}} {102.133.120.0/21 {}} {102.133.128.0/18 {}} {102.133.192.0/19 {}} {102.133.224.0/20 {}} {102.133.240.0/25 {}} {102.133.240.128/26 {}} {102.133.248.0/21 {}} {102.133.64.0/19 {}} {102.133.96.0/20 {}} {102.37.0.0/20 {}} {102.37.128.0/19 {}} {102.37.16.0/21 {}} {102.37.160.0/21 {}} {102.37.192.0/18 {}} {102.37.24.0/23 {}} {102.37.26.0/27 {}} {102.37.26.32/27 {}} {102.37.32.0/19 {}}

Is there an easy way to formulate the data to be more like a list, with line breaks, and without the brackets?

Thank you in advance for any suggestions.

  • I managed to remove the brackets by simply getting the values. iRule looks like this now:

    when HTTP_REQUEST {
        HTTP::version 1.0
        HTTP::header remove Accept-Encoding
        switch -glob [string tolower [HTTP::uri]] {
        "/azure.html" {
           # Retrieve the Azure datagroup contents, send it in a HTTP 200 response
    	   HTTP::respond 200 content [class names azure_ipv4_dg] "Content-Type" "text/html"
           }
        }
    }

    It now gives me something like this:

    102.133.0.0/18 102.133.112.0/28 102.133.120.0/21 102.133.128.0/18 102.133.192.0/19 102.133.224.0/20 102.133.240.0/25 102.133.240.128/26 102.133.248.0/21 102.133.64.0/19 102.133.96.0/20 102.37.0.0/20 102.37.128.0/19 102.37.16.0/21 102.37.160.0/21 102.37.192.0/18 102.37.24.0/23 102.37.26.0/27 102.37.26.32/27 102.37.32.0/19 102.37.64.0/21 102.37.72.0/21 102.37.80.0/21 102.37.96.0/19

    So the only thing I need is to replace space with line breaks. Any ideas?

  • I am now using two v. servers. The front one uses a stream profile and this iRule:

    when HTTP_REQUEST {
        HTTP::header remove Accept-Encoding
        STREAM::disable
        virtual vs_ipv4feed_client_http
        return
    }
     
    when HTTP_RESPONSE {
        set find " "
        set replace "</br>"
        STREAM::expression "@$find@$replace@"
        STREAM::enable
    }

    The backend v. server (vs_ipv4feed_client_http) uses the iRule I pasted in the previous post as well.

    when HTTP_REQUEST {
    	switch -glob [string tolower [HTTP::uri]] {
        "/azureipv4.txt" {
           # Retrieve the Azure datagroup contents, send it in a HTTP 200 response
    	   HTTP::respond 200 content [class names azure_ipv4_dg] "Content-Type" "text/html"
           }
        }
    }

    The output looks like this now:

    102.133.0.0/18

    102.133.112.0/28

    102.133.120.0/21

    102.133.128.0/18

    102.133.192.0/19

    102.133.224.0/20

    102.133.240.0/25

    102.133.240.128/26

    102.133.248.0/21

    102.133.64.0/19

    ....

     

    Which is what I wanted. However, if I look a the source code of this txt file within the browser, it looks like this:

    102.133.0.0/18</br>102.133.112.0/28</br>102.133.120.0/21</br>102.133.128.0/18</br>102.133.192.0/19</br>102.133.224.0/20</br>102.133.240.0/25</br>102.133.240.128/26</br>102.133.248.0/21</br>102.133.64.0/19</br>102.133.96.0/20</br>102.37.0.0/20</br>102.37.128.0/19</br>.......

    My problem is that the firewall that I need to feed this list within, expects a native txt file with line breaks, rather than an html based txt file which uses "</br>". Therefore, I am unable to feed those IPs into my firewall, unless I somehow present this txt file as a native txt.