a newLISPer having trouble with web-parsing

Q&A's, tips, howto's
Locked
benbenjamin
Posts: 2
Joined: Fri Nov 23, 2012 2:55 pm

a newLISPer having trouble with web-parsing

Post by benbenjamin »

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

Code: Select all

(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

Code: Select all

("20:AA:4B")
so I know that the code "works"

but I would like to retrieve the full line of text

Code: Select all

"20:AA:4B Cisco-Li # Cisco-Linksys, LLC"
so I can parse it into

Code: Select all

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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: a newLISPer having trouble with web-parsing

Post by cormullion »

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

Code: Select all

(find-all (string routerMAC ".*")  wireshark)
which returns

Code: Select all

("0:22:6B\tCisco-Li               # Cisco-Linksys, LLC")

benbenjamin
Posts: 2
Joined: Fri Nov 23, 2012 2:55 pm

Re: a newLISPer having trouble with web-parsing

Post by benbenjamin »

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

Locked