def report_ports(target, ports):
 (ans, unans) = sr((IP(dst=target) / TCP(dport=ports)), timeout=5)
 rep = '\\begin{tabular}{|r|l|l|}\n\\hline\n'
 for (s, r) in ans:
  if (not r.haslayer(ICMP)):
   if (r.payload.flags == 18):
    rep += r.sprintf('%TCP.sport% & open & SA \\\\\n')
 rep += '\\hline\n'
 for (s, r) in ans:
  if r.haslayer(ICMP):
   rep += r.sprintf('%TCPerror.dport% & closed & ICMP type %ICMP.type%/%ICMP.code% from %IP.src% \\\\\n')
  elif (r.payload.flags != 18):
   rep += r.sprintf('%TCP.sport% & closed & TCP %TCP.flags% \\\\\n')
 rep += '\\hline\n'
 for i in unans:
  rep += i.sprintf('%TCP.dport% & ? & unanswered \\\\\n')
 rep += '\\hline\n\\end{tabular}\n'
 return rep

def report_ports ( target , ports ) : ( ans , unans ) = sr ( ( IP ( dst = target ) / TCP ( dport = ports ) ) , timeout = 5 ) rep = '\\begin{tabular}{|r|l|l|}\n\\hline\n' for ( s , r ) in ans : if ( not r . haslayer ( ICMP ) ) : if ( r . payload . flags == 18 ) : rep += r . sprintf ( '%TCP.sport% & open & SA \\\\\n' ) rep += '\\hline\n' for ( s , r ) in ans : if r . haslayer ( ICMP ) : rep += r . sprintf ( '%TCPerror.dport% & closed & ICMP type %ICMP.type%/%ICMP.code% from %IP.src% \\\\\n' ) elif ( r . payload . flags != 18 ) : rep += r . sprintf ( '%TCP.sport% & closed & TCP %TCP.flags% \\\\\n' ) rep += '\\hline\n' for i in unans : rep += i . sprintf ( '%TCP.dport% & ? & unanswered \\\\\n' ) rep += '\\hline\n\\end{tabular}\n' return rep
portscan a target and output a latex table report_ports -> string .