a newLISPer having trouble with web-parsing

Started by benbenjamin, November 23, 2012, 07:22:14 AM

Previous topic - Next topic

benbenjamin

I have written the following code, but I can not work out how to return the line that the match is found in.


(set 'wireshark "http://anonsvn.wireshark.org/wireshark/trunk/manuf")

(set 'arptable (map (fn (x) (parse x " ")) (exec "arp -a")))

(define (cleanIPaddress x)
  (slice x 1 -1))

(define (cleanMACaddress x)
  (upper-case (join (slice (parse x ":") 0 3) ":")))

(define (addIPandMACaddress x)
  (list (cleanIPaddress (nth 1 x)) (cleanMACaddress (nth 3 x))))

(set 'arplist (map addIPandMACaddress arptable))

(set 'routerMAC (last (assoc (exec "ipconfig getoption en1 router") arplist)))

(find-all routerMAC (get-url wireshark))

returns

("20:AA:4B")

so I know that the code "works"



but I would like to retrieve the full line of text


"20:AA:4B Cisco-Li # Cisco-Linksys, LLC"

so I can parse it into


( (exec "ipconfig getoption en1 router") "20:AA:4B" "Cisco-Li" "Cisco-Linksys")

cormullion

#1
Well I'm not quite sure but perhaps you could just look for the whole line:


(find-all (string routerMAC ".*")  wireshark)
which returns
("0:22:6BtCisco-Li               # Cisco-Linksys, LLC")

benbenjamin

#2
haha... yes that is exactly what I was trying to do!. Many thanks.