title: How to determine wifi hardware address in Termux
body: <p>I need to determine my device's MAC (hardware) address, ie that for the wifi. I'm using Termux on an Android device, although maybe an answer will apply more generally.</p>
  
  <p>I'm using python, but any bash would be okay too.</p>
  
  <p>On some 2017 devices, the following used to work:</p>
  
  <pre><code>import subprocess
  result = subprocess.run(['ip','link'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
  rc,so, se = result.returncode, result.stdout, result.stderr
  assert not rc
  ipl = re.split('\n[^ ]+ ', so, re.MULTILINE)
  wlanl = [L for L in ipl if L.startswith('wlan0')]
  assert wlanl
  HWadd = re.findall('link/ether (.*?) ',wlanl[0])[0].lower()
  </code></pre>
  
  <p>however, this is failing strangely (I cannot get re.split to work as I expect) on a new 2019 device.</p>
  
  <p>Instead, I now have a nearly equally ungainly alternative that works:</p>
  
  <pre><code>import subprocess
  result = subprocess.run(['ip','link'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
  rc,so, se = result.returncode, result.stdout, result.stderr
  assert not rc
  ipl =  re.findall('\n[0-9]+: wlan0:.*?\n +link/ether ([^\n]*?) .*?\n', so, re.MULTILINE+ re.DOTALL) 
  assert ipl
  HWadd = ipl[0].lower()
  </code></pre>
  
  <p>Is there a more reliable way to extract this information from the OS somewhere?</p>
  
  <p>By the way, using <code>termux-wifi-connectioninfo</code> gives:</p>
  
  <pre><code>"mac_address": "02:00:00:00:00:00"
  </code></pre>