title: Python: get the current channel of WiFi interface
body: <p>how're you doing?</p>
  
  <p>I am trying to find a simple way to get the channel of a wifi interface. Well, I found a way to do so, but it's pretty messed up and not simple at all. I've searched the internet, but nobody seems to have the same problem.</p>
  
  <p><strong>Here is how I do it:</strong></p>
  
  <p>I take the output of <code>iwlist wlan0 channel</code> which is:</p>
  
  <pre><code>wlan0     13 channels in total; available frequencies :
            Channel 01 : 2.412 GHz
            Channel 02 : 2.417 GHz
            Channel 03 : 2.422 GHz
            Channel 04 : 2.427 GHz
            Channel 05 : 2.432 GHz
            Channel 06 : 2.437 GHz
            Channel 07 : 2.442 GHz
            Channel 08 : 2.447 GHz
            Channel 09 : 2.452 GHz
            Channel 10 : 2.457 GHz
            Channel 11 : 2.462 GHz
            Channel 12 : 2.467 GHz
            Channel 13 : 2.472 GHz
            Current Frequency:2.427 GHz (Channel 4)
  </code></pre>
  
  <p>You can clearly see the channel (currently Channel 4).</p>
  
  <p>I'm using the <code>subprocess</code>-module to get the output:</p>
  
  <pre><code>stdout = Popen('iwlist ' + iface + ' channel', shell=True, stdout=PIPE).stdout
  output = stdout.read()
  channel = output[-5:-3].replace(' ', '')
  </code></pre>
  
  <p>The output is exactly what I want, but the way to get it is too complicated. I also don't want to use any shell commands...</p>
  
  <p>Is there another way? Thank you in advance!</p>