title: Python Nmap Parser
body: <p>I'm playing with the nmap parser for python located at (<a href="http://xael.org/norman/python/python-nmap/" rel="nofollow">http://xael.org/norman/python/python-nmap/</a>). It provides a sample code snippet that I used in a .py script in order to do routine checks, automating some tasks. However I get a error on "Line 25". Can someone please help me..? </p>
  
  <pre><code>import nmap
  
  nm = nmap.PortScanner()
  
  nm.scan('127.0.0.1', '22-2223')
  nm.command_line()
  nm.scaninfo()
  
  for host in nm.all_hosts():
      print('----------------------------------------------------')
      print('Host : %s (%s)' % (host, nm[host].
      print('State : %s' % nm[host].state())
      for proto in nm[host].all_protocols():
           print('----------')
           print('Protocol : %s' % proto)
           lport = nm[host][proto].keys()
           lport.sort()
           for port in lport:
               print ('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))
               print('----------------------------------------------------')
  </code></pre>
  
  <p>ERROR Below:</p>
  
  <pre><code>    root@server:~/python/python# python MyApp.py 
      ----------------------------------------------------
      Host : 127.0.0.1 (localhost)
      State : up
      ----------
      Protocol : addresses
      Traceback (most recent call last):
        File "MyApp.py", line 25, in &lt;module&gt;
          print ('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))
      TypeError: string indices must be integers
      root@damnation:~/python/python# 
  </code></pre>
  
  <p>Line 25, is the second last print line from the bottom. 'port : %s\tstate : %s' % (port, nm[host][proto][port]'.</p>
  
  <p>any advice would be great. thank you . </p>