I need to parse an avahi browse result for some information in PHP. I am NOT basing this on "parsable" Avahi browse (-p) as this seems more difficult to parse than the unparsable, unless I am mistaken.
As I can limit the browse to certain types , I think that I need only draw the IP:port and device name from the strings. Prefer IPV4. The example does not have an IPV6 but some searches do, but I think there will always be an IPV4, correct? It is probably safe to use IPV4 only.
+ wlp61s0 IPv6 Canon MG5700 series _uscan._tcp local
+ wlp61s0 IPv4 Canon MG5700 series _uscan._tcp local
= wlp61s0 IPv6 Canon MG5700 series _uscan._tcp local
hostname = [ED122D000000.local]
address = [192.168.0.252]
port = [80]
txt = ["duplex=F" "is=platen" "cs=grayscale,color" "rs=eSCL" "representation=http://ED122D000000.local./icon/printer_icon.png" "vers=2.5" "UUID=00000000-0000-1000-8000-00BBC1ED122D" "adminurl=http://ED122D000000.local./index.html?page=PAGE_AAP" "note=Rich's office" "pdl=image/jpeg,application/pdf" "ty=Canon MG5700 series" "txtvers=1"]
= wlp61s0 IPv4 Canon MG5700 series _uscan._tcp local
hostname = [ED122D000000.local]
address = [192.168.0.252]
port = [80]
txt = ["duplex=F" "is=platen" "cs=grayscale,color" "rs=eSCL" "representation=http://ED122D000000.local./icon/printer_icon.png" "vers=2.5" "UUID=00000000-0000-1000-8000-00BBC1ED122D" "adminurl=http://ED122D000000.local./index.html?page=PAGE_AAP" "note=Rich's office" "pdl=image/jpeg,application/pdf" "ty=Canon MG5700 series" "txtvers=1"]
edit-------------------------------- @Martn Zetler yes that works in originally posted string, but not in this one. Also as commenteed to another poster, the order does change, so using the parsable format with no descriptors would be unreliable.
+ eth0 IPv6 HP LaserJet MFP M130nw (Bonjour) _uscan._tcp local
+ eth0 IPv4 HP LaserJet MFP M130nw (Bonjour) _uscan._tcp local
= eth0 IPv6 HP LaserJet MFP M130nw (Bonjour) _uscan._tcp local
hostname = [NPIA9BA52.local]
address = [192.168.1.2]
port = [8080]
txt = ["note=Vallarta" "duplex=F" "is=platen" "cs=color,grayscale" "pdl=application/pdf,image/jpeg" "uuid=564e4234-4430-3737-3739-c8d3ffa9ba52" "rs=eSCL" "representation=http://NPIA9BA52.local/ipp/images/printer.png" "vers=2.5" "usb_MDL=HP LaserJet MFP M129-M134" "usb_MFG=HP" "mdl=LaserJet MFP M129-M134" "mfg=HP" "ty=HP LaserJet MFP M129-M134" "adminurl=http://NPIA9BA52.local." "txtvers=1"]
= eth0 IPv4 HP LaserJet MFP M130nw (Bonjour) _uscan._tcp local
hostname = [NPIA9BA52.local]
address = [192.168.1.2]
port = [8080]
txt = ["note=Vallarta" "duplex=F" "is=platen" "cs=color,grayscale" "pdl=application/pdf,image/jpeg" "uuid=564e4234-4430-3737-3739-c8d3ffa9ba52" "rs=eSCL" "representation=http://NPIA9BA52.local/ipp/images/printer.png" "vers=2.5" "usb_MDL=HP LaserJet MFP M129-M134" "usb_MFG=HP" "mdl=LaserJet MFP M129-M134" "mfg=HP" "ty=HP LaserJet MFP M129-M134" "adminurl=http://NPIA9BA52.local." "txtvers=1"]