OPNsense Forum

English Forums => Tutorials and FAQs => Topic started by: franciz on March 20, 2023, 05:03:43 PM

Title: Convert PFsense DHCP static addresses via regex
Post by: franciz on March 20, 2023, 05:03:43 PM
1) Save PFsense config file
2) Go to https://regex101.com/
3) Select flavor "PCRE2" and function "List"
4) In "Test string" paste the contents of the backup file.
5) In "Regular Expression" paste the following:
<staticmap>\n\t+<mac>(.+)<\/mac>\n\t+(?:.*)\n\t+<ipaddr>(.+)<\/ipaddr>\n\t+<hostname>(.+)<\/hostname>\n\t+<descr><!\[CDATA\[(.+)\]\]><\/descr>
6) In "Function" paste the following:
\t\t\t<staticmap>\n\t\t\t\t<mac>$1</mac>\n\t\t\t\t<ipaddr>$2</ipaddr>\n\t\t\t\t<hostname>$3</hostname>\n\t\t\t\t<descr>$4</descr>\n\t\t\t</staticmap>\n
7) You will get the converted file below. You have to add the xml header and footer to this results:
<?xml version="1.0"?>
<opnsense>
<dhcpd>
    <lan>
********** The converted result*************
    </lan>
  </dhcpd>
</opnsense>


I hope this helps someone. I tried with uprt (https://github.com/GeekVisit/uproot) and got all the results mangled...
Title: Re: Convert PFsense DHCP static addresses via regex
Post by: TheAutomationGuy on March 20, 2023, 09:09:38 PM
I'm currently trying OPNsense in a lab setting and considering making the change myself.  This will come in handy.  Thanks for posting!
Title: Re: Convert PFsense DHCP static addresses via regex
Post by: cyber7 on March 24, 2025, 12:56:29 PM
I have just used your process and for me, it worked!  Thank you!