title: How do I get ip address and mac address from arp output via Python regex?
body: <p>I would like to get mac addresses and corresponding ip addresses (e.g. as a dictionary with mac address as keys and ip addresses) as value from <code>arp</code> command line output on Ubuntu.</p>
  
  <pre><code>$ arp
  Address                  HWtype  HWaddress           Flags Mask            Iface
  XX.X.X.X(XX)                ether   XX:XX:XX:XX:XX:XX   C                     eth0
  &lt;host name&gt;                 ether   XX:XX:XX:XX:XX:XX   C                     eth0
  </code></pre>
  
  <p>The regex for ip addresses <code>(?P&lt;ip&gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</code> and the regex for macs <code>(?P&lt;mac&gt;[0-9a-f]{2}[:]){5}([0-9a-f]{2})</code> each for it alone works fine. How can I combine those two and ignore everything between ip addresses and macs? How could I improve the ip address regex to match host names as well? In case there is a better alternative to using <code>arp</code> to get both, ip address and macs I am happy to use this command instead.</p>