
Sc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z g  e j D] Z d e k rj e ^ qR e _ d  d l Z d  d l	 Z d  d l
 Z d  d l m Z e a d Z d e j j j f d     YZ d e f d     YZ d	 e f d
     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z e j d  Z d   Z  d   Z! d e f d     YZ" d e" f d      YZ# d! e" f d"     YZ$ d# e f d$     YZ% d% e f d&     YZ& d' e f d(     YZ' d) e f d*     YZ( d+   Z) d, e j j j* f d-     YZ+ d. e j j, j- f d/     YZ. d0   Z/ d1 Z0 d2 Z1 d3 Z2 d4   Z3 d5   Z4 d6   Z5 e6 d7 k re5 e _5 e j7 e4    n  d S(8   iNt   _xmlplus(   t   StringIOu   1t   OverrideEntityResolverc           B   s    e  Z d  Z e   Z d   Z RS(   sq   This class overrides the default behavior of xml.sax to download
    remote DTDs, instead returning blank stringsc         C   s   t  j S(   N(   R   t   empty(   t   selft   publicIdt   systemId(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   resolveEntity)   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   $   s   	t   Scanc           B   sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   A single Nmap scan, corresponding to a single invocation of Nmap. It is
    a container for a list of hosts. It also has utility methods to load itself
    from an Nmap XML file.c         C   sL   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ g  |  _ g  |  _ g  |  _ d  S(   N(	   t   Nonet   scannert   versiont   argst
   start_datet   end_datet   hostst   pre_script_resultst   post_script_results(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   __init__1   s    							c         C   s   |  j  j d d    d  S(   Nt   keyc         S   s
   |  j    S(   N(   t   get_id(   t   h(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   <lambda><   s    (   R   t   sort(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt
   sort_hosts;   s    c         C   sI   t  j j   } t |   } | j t    | j |  | j |  d S(   s8   Load a scan from the Nmap XML in the file-like object f.N(   t   xmlt   saxt   make_parsert   NmapContentHandlert   setEntityResolverR   t   setContentHandlert   parse(   R   t   ft   parsert   handler(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   load>   s
    c         C   s2   t  | d  } z |  j |  Wd | j   Xd S(   s;   Load a scan from the Nmap XML file with the given filename.t   rN(   t   openR&   t   close(   R   t   filenameR#   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   load_from_fileF   s    c         C   s   i  } |  j  d  k	 r% |  j  | d <n  |  j d  k	 rD |  j | d <n  |  j d  k	 r d t j |  j j    | d <|  j j d  | d <n  |  j d  k	 r |  j | d <n  | j	 d |  d  S(	   Nu   scanneru   argss   %du   starts   %a %b %d %H:%M:%S %Yu   startstru   versionu   nmaprun(
   R   R   R   R   t   timet   mktimet	   timetuplet   strftimeR   t   startElement(   R   t   writert   attrs(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   write_nmaprun_openN   s     	c         C   s   | j  d  d  S(   Nu   nmaprun(   t
   endElement(   R   R1   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   write_nmaprun_close\   s    c         C   s   | j    } | j d  } |  j d  k	 r@ | j d |  j  n  |  j d  k	 re | j d |  j  n  |  j d  k	 r | j d d t j |  j j	     | j d |  j j
 d   n  |  j d  k	 r | j d |  j  n  | j |  | S(	   Nu   nmaprunu   scanneru   argsu   starts   %du   startstrs   %a %b %d %H:%M:%S %Yu   version(   t   createDocumentFragmentt   createElementR   R   t   setAttributeR   R   R,   R-   R.   R/   R   t   appendChild(   R   t   documentt   fragt   elem(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   nmaprun_to_dom_fragment_   s      (
   R   R	   R
   R   R   R&   R+   R3   R5   R=   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   -   s   	
					t   Hostc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z RS(   s   A single host, with a state, addresses, host names, a dict mapping port
    specs to Ports, and a list of OS matches. Host states are strings, or None
    for "unknown".c         C   sC   d  |  _ g  |  _ g  |  _ i  |  _ i  |  _ g  |  _ g  |  _ d  S(   N(   R   t   statet	   addressest	   hostnamest   portst
   extraportst   ost   script_results(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   v   s    						c         C   sb   t  |  j  d k r, t t |  j  d  St  |  j  d k rX t t |  j  d  St |   S(   sT   Return an id that is used to determine if hosts are "the same"
        across scans.i    (   t   lenR@   t   strt   sortedRA   t   id(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR      s
    c         C   s   d j  d   t |  j  D  } d j  t |  j   } t |  d k rs t |  d k rl d | | f S| Sn t |  d k r | Sd Sd S(   s1   Return a human-readable identifier for this host.u   , c         s   s   |  ] } | j  Vq d  S(   N(   t   s(   t   .0t   a(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pys	   <genexpr>   s    i    u   %s (%s)u	   <no name>N(   t   joinRH   R@   RA   RF   (   R   t	   address_st
   hostname_s(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   format_name   s    "c         C   s   | |  j  | j <d  S(   N(   RB   t   spec(   R   t   port(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   add_port   s    c         C   s&   | |  j  k r" |  j  j |  n  d  S(   N(   R@   t   append(   R   t   address(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   add_address   s    c         C   s&   | |  j  k r" |  j  j |  n  d  S(   N(   RA   RT   (   R   t   hostname(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   add_hostname   s    c         C   s   | d  k p | |  j k S(   N(   R   RC   (   R   R?   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   is_extraports   s    c         C   sn   g  |  j  j   D] \ } } | | f ^ q } | j d t  d j g  | D] \ } } d | | f ^ qK  S(   Nt   reverseu   , u   %d %s ports(   RC   t   itemsR   t   TrueRM   (   R   R?   t   countt   list(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   extraports_string   s    .c         C   sQ   | j    } |  j d  k	 rM | j d  } | j d |  j  | j |  n  | S(   Nu   statusu   state(   R6   R?   R   R7   R8   R9   (   R   R:   R;   R<   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   state_to_dom_fragment   s    c         C   s<   | j    } | j d  } | j d |  | j |  | S(   Nu   hostnameu   name(   R6   R7   R8   R9   (   R   R:   RW   R;   R<   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   hostname_to_dom_fragment   s
    c         C   sr   | j    } x_ |  j j   D]N \ } } | j d  } | j d |  | j d t |   | j |  q W| S(   Nu
   extraportsu   stateu   count(   R6   RC   R[   R7   R8   t   unicodeR9   (   R   R:   R;   R?   R]   R<   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   extraports_to_dom_fragment   s    c         C   s<   | j    } | j d  } | j d |  | j |  | S(   Nu   osmatchu   name(   R6   R7   R8   R9   (   R   R:   RD   R;   R<   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   os_to_dom_fragment   s
    c         C   s*  | j    } | j d  } |  j d  k	 rC | j |  j |   n  x' |  j D] } | j | j |   qM Wt |  j	  d k r | j d  } x* |  j	 D] } | j |  j
 | |   q W| j |  n  | j d  } | j |  j |   xH t |  j j    D]1 } |  j | j  s	| j | j |   q	q	W| j   rZ| j |  n  t |  j  d k r| j d  }	 x* |  j D] }
 |	 j |  j | |
   qW| j |	  n  t |  j  d k r| j d  } x' |  j D] } | j | j |   qW| j |  n  | j |  | S(   Nu   hosti    u	   hostnamesu   portsu   osu
   hostscript(   R6   R7   R?   R   R9   R`   R@   t   to_dom_fragmentRF   RA   Ra   Rc   RH   RB   t   valuesRY   t   hasChildNodesRD   Rd   RE   (   R   R:   R;   R<   t   addrt   hostnames_elemRW   t
   ports_elemRR   t   os_elemRD   t   hostscript_elemt   sr(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe      s>    (   R   R	   R
   R   R   RP   RS   RV   RX   RY   R_   R`   Ra   Rc   Rd   Re   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR>   r   s   															t   Addressc           B   se   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 e
 e	  Z	 d   Z RS(	   c         C   s   | |  _  d  S(   N(   RJ   (   R   RJ   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR      s    c         C   s   |  j  |  d k S(   Ni    (   t   __cmp__(   R   t   other(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   __eq__   s    c         C   s   |  j  |  S(   N(   Rq   (   R   Rp   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   __ne__   s    c         C   s   t  |  j    S(   N(   t   hasht   sort_key(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   __hash__   s    c         C   s   t  |  j   | j    S(   N(   t   cmpRt   (   R   Rp   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRo      s    c         C   s   t  |  j  S(   N(   RG   RJ   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   __str__  s    c         C   s   |  j  S(   N(   RJ   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   __unicode__  s    c         C   sV   |  d k r t  |  S|  d k r, t |  S|  d k rB t |  St d |    d  S(   Nu   ipv4u   ipv6u   macu   Unknown address type %s.(   t   IPv4Addresst   IPv6Addresst
   MACAddresst
   ValueError(   t   typeRJ   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   new	  s    


c         C   sR   | j    } | j d  } | j d |  j  | j d |  j  | j |  | S(   Nu   addressu   addru   addrtype(   R6   R7   R8   RJ   R}   R9   (   R   R:   R;   R<   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe     s    (   R   R	   R   Rq   Rr   Ru   Ro   Rw   Rx   R~   t   staticmethodRe   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRn      s   									Ry   c           B   s    e  Z e d     Z d   Z RS(   c         C   s   d S(   Nu   ipv4(    (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   !  s    c         C   s   d |  j  f S(   Ni    (   RJ   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRt   #  s    (   R   R	   t   propertyR}   Rt   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRy      s   Rz   c           B   s    e  Z e d     Z d   Z RS(   c         C   s   d S(   Nu   ipv6(    (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   (  s    c         C   s   d |  j  f S(   Ni   (   RJ   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRt   *  s    (   R   R	   R   R}   Rt   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRz   '  s   R{   c           B   s    e  Z e d     Z d   Z RS(   c         C   s   d S(   Nu   mac(    (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   /  s    c         C   s   d |  j  f S(   Ni   (   RJ   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRt   1  s    (   R   R	   R   R}   Rt   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR{   .  s   t   Portc           B   s>   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z RS(   s   A single port, consisting of a port specification, a state, and a
    service version. A specification, or "spec," is the 2-tuple (number,
    protocol). So (10, "tcp") corresponds to the port 10/tcp. Port states are
    strings, or None for "unknown".c         C   s+   | |  _  | |  _ t   |  _ g  |  _ d  S(   N(   RQ   R?   t   Servicet   serviceRE   (   R   RQ   R?   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   :  s    		c         C   s$   |  j  d  k r d St |  j   Sd  S(   Nu   unknown(   R?   R   Rb   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   state_string@  s    c         C   s   d |  j  S(   Nu   %d/%s(   RQ   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   spec_stringF  s    c         C   sV   t  |  j | j  } | d k r% | St  |  j |  j |  j f | j | j | j f  S(   Ni    (   Rv   RQ   R   RE   (   R   Rp   t   d(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRo   I  s
    c         C   s   | j    } | j d  } | j d t |  j d   | j d |  j d  |  j d  k	 r | j d  } | j d |  j  | j |  n  | j |  j j	 |   x' |  j
 D] } | j | j	 |   q W| j |  | S(   Nu   portu   portidi    u   protocoli   u   state(   R6   R7   R8   Rb   RQ   R?   R   R9   R   Re   RE   (   R   R:   R;   R<   t
   state_elemRm   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe   P  s    N(	   R   R	   R
   R   R   R   R   Ro   Re   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   5  s   			R   c           B   sJ   e  Z d  Z d   Z d Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   sj   A service version as determined by -sV scan. Also contains the looked-up
    port name if -sV wasn't used.c         C   s1   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   R   t   namet   productR   t	   extrainfot   tunnel(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   c  s
    				c         C   sF   |  j  | j  k oE |  j | j k oE |  j | j k oE |  j | j k S(   N(   R   R   R   R   (   R   Rp   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRq   p  s    c         C   s   |  j  |  S(   N(   Rq   (   R   Rp   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRr   v  s    c         C   sq   g  } |  j  d  k	 r( | j |  j   n  |  j d  k	 rJ | j |  j  n  t |  d k r` d  Sd j |  Sd  S(   Ni    u   /(   R   R   RT   R   RF   RM   (   R   t   parts(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   name_stringy  s    c         C   s   g  } |  j  d k	 r( | j |  j   n  |  j d k	 rJ | j |  j  n  |  j d k	 rp | j d |  j  n  t |  d k r d Sd j |  Sd S(   s7   Get a string like in the VERSION column of Nmap output.u   (%s)i    u    N(   R   R   RT   R   R   RF   RM   (   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   version_string  s    c         C   s   | j    } | j d  } x? d D]7 } t |  |  } | d  k rI q" n  | j | |  q" Wt | j  d k r | j |  n  | S(	   Nu   serviceu   nameu   productu   versionu	   extrainfou   tunneli    (   u   nameu   productu   versionu	   extrainfou   tunnel(   R6   R7   t   getattrR   R8   RF   t
   attributesR9   (   R   R:   R;   R<   t   attrt   v(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe     s    N(   R   R	   R
   R   R   Ru   Rq   Rr   R   R   Re   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   `  s   					t   ScriptResultc           B   sD   e  Z d    Z d Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   s   d  |  _ d  |  _ d  S(   N(   R   RI   t   output(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    	c         C   s"   |  j  | j  k o! |  j | j k S(   N(   RI   R   (   R   Rp   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRq     s    c         C   s   |  j  |  S(   N(   Rq   (   R   Rp   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRr     s    c         C   s%   t  |  j |  j f | j | j f  S(   N(   Rv   RI   R   (   R   Rp   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRo     s    c         C   s   g  } |  j  j   } t |  d k rC |  j d | d | d <n  x# | d  D] } | j d |  qN Wt |  d k r | j d | d  n  | S(   Ni    u   : iu   |  u   |_ (   R   t
   splitlinesRF   RI   RT   (   R   t   resultt   linest   line(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt	   get_lines  s    c         C   sR   | j    } | j d  } | j d |  j  | j d |  j  | j |  | S(   Nu   scriptu   idu   output(   R6   R7   R8   RI   R   R9   (   R   R:   R;   R<   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe     s    N(
   R   R	   R   R   Ru   Rq   Rr   Ro   R   Re   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s   					c         C   s   d } |  j  d k	 r0 |  j  d k r0 |  j  } n  | g } |  j d k	 r[ | j |  j  n  | j d  |  j d k	 r | j d |  j j d   n  |  j d k	 r | j d |  j  n  d j |  S(	   s4   Format a startup banner more or less like Nmap does.u   Nmapu   nmapu   scanu   initiated %ss   %a %b %d %H:%M:%S %Yu   as: %su    N(   R   R   R   RT   R   R/   R   RM   (   t   scanR   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   format_banner  s    	c         C   s   t  d  } x | D] } | j |  q Wt |  d k r | Jt |  d k rc | d |  IJn1 t |  d k r | d |  IJn | d |  IJ| | IJn  d  S(   Nu   *i    u   -%s:u   +%s:u    %s:(   t   Tablet   append_to_port_tableRF   (   t   titlet   script_results_at   script_results_bt   script_result_diffsR#   t   tablet   sr_diff(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   print_script_result_diffs_text  s    c   	      C   s  t  |  d k r. t  |  d k r. | j   St  |  d k r | j d  } x$ | D] } |  j | j |   qV W| j |   | St  |  d k r | j d  } x$ | D] } |  j | j |   q W| j |   | Sx$ | D] } |  j | j |   q W|  Sd  S(   Ni    u   au   b(   RF   R6   R7   R9   Re   (	   R<   R   R   R   R:   t   a_elemRm   t   b_elemR   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt#   script_result_diffs_to_dom_fragment  s"    $
c         c   sJ  d } d } x | t  |   k  r | t  |  k  r |  | j   | | j   k  rr |  | t   f V| d 7} q |  | j   | | j   k r t   | | f V| d 7} q |  | | | f V| d 7} | d 7} q Wx2 | t  |   k  r|  | t   f V| d 7} q Wx2 | t  |  k  rEt   | | f V| d 7} qWd S(   sK  Take hosts lists a and b, which must be sorted by id, and return pairs.
    When the heads of both lists have the same ids, they are returned together.
    Otherwise the one with the smaller id is returned, with an empty host as
    its counterpart, and the one with the higher id will remain in its list for
    a later iteration.i    i   N(   RF   R   R>   (   RL   t   bt   it   j(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt
   host_pairs  s$    '  
t   ScanDiffc           B   s&   e  Z d  Z e j d  Z d   Z RS(   se   An abstract class for different diff output types. Subclasses must
    define various output methods.c         C   s   | |  _  | |  _ | |  _ d S(   sJ   Create a ScanDiff from the "before" scan_a and the "after"
        scan_b.N(   t   scan_at   scan_bR#   (   R   R   R   R#   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    		c         C   s  |  j  j   |  j j   |  j   t j |  j  j |  j j  } |  j |  d } xv t |  j  j	 |  j j	  D]Y \ } } t
 | |  } | | j 7} | j d k s t rq | p | } |  j |  qq qq Wt j |  j  j |  j j  } |  j |  |  j   | S(   Ni    (   R   R   R   t   output_beginningt   ScriptResultDifft
   diff_listsR   t   output_pre_scriptsR   R   t   HostDifft   costt   verboset   output_host_diffR   t   output_post_scriptst   output_ending(   R   t   pre_script_result_diffsR   t   host_at   host_bt   h_difft   hostt   post_script_result_diffs(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   !  s&    
(	
(   R   R	   R
   t   syst   stdoutR   R   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s   t   ScanDiffTextc           B   sD   e  Z e j d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   s   t  j |  | | |  d  S(   N(   R   R   (   R   R   R   R#   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   @  s    c         C   sm   t  |  j  } t  |  j  } | | k rO |  j d | IJ|  j d | IJn t ri |  j d | IJn  d  S(   Nu   -%su   +%su    %s(   R   R   R   R#   R   (   R   t   banner_at   banner_b(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   C  s    c         C   s)   t  d |  j j |  j j | |  j  d  S(   Ns   Pre-scan script results(   R   R   R   R   R#   (   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   L  s    c         C   s)   t  d |  j j |  j j | |  j  d  S(   Ns   Post-scan script results(   R   R   R   R   R#   (   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   Q  s    c         C   s   |  j  J| j |  j   d  S(   N(   R#   t
   print_text(   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   V  s    c         C   s   d  S(   N(    (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   Z  s    (
   R   R	   R   R   R   R   R   R   R   R   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   ?  s   					t   ScanDiffXMLc           B   sM   e  Z e j d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   c         C   sS   t  j |  | | |  t j j j   } | j d  d  d   |  _ t	 |  |  _
 d  S(   N(   R   R   R   t   domt   minidomt   getDOMImplementationt   createDocumentR   R:   t	   XMLWriterR1   (   R   R   R   R#   t   impl(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   _  s    c         C   sC   x< d D]4 } t  |  j | d   t  |  j | d   k r t Sq Wt S(   NR   R   R   R   R   (   s   scanners   versions   argss
   start_dates   end_date(   R   R   R   R   R\   t   False(   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   nmaprun_differsg  s
    c         C   s   |  j  j   |  j  j d i t d 6 |  j  j d i   |  j   r |  j  j |  j j |  j   |  j  j	 |  j
 j |  j   n( t r |  j  j |  j j |  j   n  d  S(   Nu   nmapdiffu   versionu   scandiff(   R1   t   startDocumentR0   t   NDIFF_XML_VERSIONR   t   frag_aR   R=   R:   t   frag_bR   R   R;   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   n  s    			c         C   sr   t  |  d k s t rn |  j j d  } t | |  j j |  j j | |  j  } |  j j	 |  | j
   n  d  S(   Ni    u	   prescript(   RF   R   R:   R7   R   R   R   R   R1   R;   t   unlink(   R   R   t   prescript_elemR;   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   |  s    c         C   sr   t  |  d k s t rn |  j j d  } t | |  j j |  j j | |  j  } |  j j	 |  | j
   n  d  S(   Ni    u
   postscript(   RF   R   R:   R7   R   R   R   R   R1   R;   R   (   R   R   t   postscript_elemR;   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    c         C   s0   | j  |  j  } |  j j |  | j   d  S(   N(   Re   R:   R1   R;   R   (   R   R   R;   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    c         C   s1   |  j  j d  |  j  j d  |  j  j   d  S(   Nu   scandiffu   nmapdiff(   R1   R4   t   endDocument(   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    (   R   R	   R   R   R   R   R   R   R   R   R   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   ^  s   			
	
	R   c           B   sA   e  Z d  Z d   Z d   Z d   Z e j d  Z d   Z	 RS(   s   A diff of two Hosts. It contains the two hosts, variables describing
    what changed, and a list of PortDiffs and OS differences.c         C   sq   | |  _  | |  _ t |  _ t |  _ t |  _ t |  _ g  |  _ i  |  _ g  |  _	 g  |  _
 d |  _ |  j   d  S(   Ni    (   R   R   R   t   state_changedt
   id_changedt
   os_changedt   extraports_changedRB   t
   port_diffst   os_diffsR   R   t   diff(   R   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    											c         C   s  |  j  j |  j j k r3 t |  _ |  j d 7_ n  t |  j  j  t |  j j  k s{ t |  j  j  t |  j j  k r t |  _	 |  j d 7_ n  t
 t |  j  j j    j t |  j j j      } | j   x | D] } |  j  j j |  } |  j j j |  } t | p"t |  | p1t |   } |  j |  r | pO| } |  j j |  | |  j | <|  j | j 7_ q q Wt j d  |  j  j |  j j  } | j   |  _ t g  |  j D] } | d d k r| ^ q }	 |	 d k rt |  _ n  |  j |	 7_ t d   |  j  j j   D  }
 t d   |  j j j   D  } |
 | k r|t |  _  |  j d 7_ n  t! j" |  j  j# |  j j#  |  _$ |  j t |  j$  7_ d  S(   Ni   i    t   equalc         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   RK   R?   R]   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pys	   <genexpr>  s   c         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   RK   R?   R]   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pys	   <genexpr>  s   (%   R   R?   R   R\   R   R   t   setR@   RA   R   R^   RB   t   keyst   unionR   t   gett   PortDiffR   t   include_diffRT   R   t   difflibt   SequenceMatcherR   RD   t   get_opcodesR   RF   R   t   tupleRC   R[   R   R   R   RE   R   (   R   t	   all_specsRQ   t   port_at   port_bR   RR   R   t   xt   os_costt   extraports_at   extraports_b(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     sJ    	$$	
'2			c         C   sK   |  j  j | j j  r4 |  j j | j j  r4 t St r> t S| j	 d k S(   Ni    (
   R   RY   R   R?   R   R   R   R   R\   R   (   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    c         C   s  |  j  } |  j } |  j rm | j d  k	 rA | d | j   IJn  |  j j d  k	 r | d | j   IJq n | d | j   IJ|  j r | j d  k	 r | d | j IJn  | j d  k	 r | d | j IJq n t r | d | j IJn  |  j rQt	 | j
  d k r"| d | j   IJn  t	 | j
  d k r| d	 | j   IJqn5 t rt	 | j
  d k r| d
 | j   IJqn  t d  } | j d  k rd } n | j d  k rd } n d } | j | d d d d f  x1 |  j D]& } |  j | } | j | | |  qWt	 |  d k r7| | IJn  |  j sFt rt	 | j  d k rt	 | j  d k r}| d IJq| d IJn" t	 | j  d k r| d IJn  x |  j D] \ } }	 }
 } } | d k s| d k rx/ t |	 |
  D] } | d | j | IJqWn  | d k s-| d k r_x/ t | |  D] } | d | j | IJq=Wn  | d k rx/ t |	 |
  D] } | d | j | IJq{WqqWn  t d | j | j |  j  d  S(   Nu   -%s:u   +%s:u    %s:u   -Host is %s.u   +Host is %s.u    Host is %s.i    u   -Not shown: %su   +Not shown: %su    Not shown: %su   ** * * *u   +u   -u    u   PORTu   STATEu   SERVICEu   VERSIONi   u    OS details:u   -OS details:u   +OS details:t   replacet   deletes   -  %st   inserts   +  %sR   s      %ss   Host script results(   R   R   R   R?   R   RP   R   R   R   RF   RC   R_   R   RT   RB   R   R   R   RD   R   t   rangeR   RE   R   (   R   R#   R   R   t
   port_tablet   markRR   t	   port_difft   opt   i1t   i2t   j1t   j2R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     sn    							#c         C   s  |  j  } |  j } | j   } | j d  } | j |  | j d  k sX | j d  k r | j d  k	 r | j d  } | j | j |   | j |  nD | j d  k	 r | j d  } | j | j |   | j |  n  | S| j d  } | j | j k r't r| j | j	 |   qnd | j d  } | j | j	 |   | j |  | j d  } | j | j	 |   | j |  t
 | j  }	 t
 | j  }
 x3 t |	 j |
   D] } | j | j |   qW| j d  } x. t |	 |
  D] } | j | j |   qW| j   r;| j |  n  | j d  } x. t |
 |	  D] } | j | j |   q[W| j   r| j |  n  | j d  } t
 | j  } t
 | j  } x6 t | j |   D] } | j | j | |   qW| j d  } x1 t | |  D] } | j | j | |   qW| j   r\| j |  n  | j d  } x1 t | |  D] } | j | j | |   q|W| j   r| j |  n  | j   r| j |  n  | j d  } | j | j k r| j | j |   nd | j d  } | j | j |   | j |  | j d  } | j | j |   | j |  xe |  j D]Z } |  j | } | j d k rt r| j | j |   qq| j | j |   qW| j   r| j |  n  |  j st r| j d  } xK|  j D]@\ } } } } } | d	 k sN| d
 k r| j d  } x7 t | |  D]& } | j | j | | j |   qmW| j |  n  | d	 k s| d k r| j d  } x7 t | |  D]& } | j | j | | j |   qW| j |  n  | d k r!x: t | |  D]& } | j | j | | j |   q4Wq!q!W| j   r| j |  qn  t |  j  d k st r| j d  } | j t | | j | j |  j |   n  | j |  | S(   Nu   hostdiffu   au   bu   hostu	   hostnamesu   portsi    u   osR   R   R   R   u
   hostscript(   R   R   R6   R7   R9   R?   R   Re   R   R`   R   R@   RH   t   intersectionRg   RA   Ra   RC   Rc   RB   R   R   R   R   R   Rd   RD   RF   R   R   RE   (   R   R:   R   R   R;   t   hostdiff_elemR   R   t	   host_elemt	   addrset_at	   addrset_bRh   Ri   t   hostnameset_at   hostnameset_bRW   Rj   RR   t   p_diffRk   R   R   R   R   R   R   Rl   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe   1  s    				(
   R   R	   R
   R   R   R   R   R   R   Re   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s   		/	
KR   c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   A diff of two Ports. It contains the two ports and the cost of changing
    one into the other. If the cost is 0 then the two ports are the same.c         C   s2   | |  _  | |  _ g  |  _ d |  _ |  j   d  S(   Ni    (   R   R   R   R   R   (   R   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s
    				c         C   s   |  j  j |  j j k r* |  j d 7_ n  |  j  j |  j j k rT |  j d 7_ n  |  j  j |  j j k r~ |  j d 7_ n  t j |  j  j |  j j  |  _	 |  j t
 |  j	  7_ d  S(   Ni   (   R   RQ   R   R   R?   R   R   R   RE   R   RF   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    c         C   s0  |  j  j   |  j  j   |  j  j j   |  j  j j   g } |  j j   |  j j   |  j j j   |  j j j   g } | | k r t s |  j d k r| j	 d g |  qnX | j
 |  j  j  s | j	 d g |  n  | j
 |  j j  s| j	 d g |  n  x |  j D] } | j |  qWd S(   s   Append this port diff to a Table containing five columns:
            +- PORT STATE SERVICE VERSION
        The "+-" stands for the diff indicator column.i    u    u   -u   +N(   R   R   R   R   R   R   R   R   R   RT   RY   R?   R   (   R   R   R   R   t	   a_columnst	   b_columnsR   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s"    c   	      C   s7  | j    } | j d  } | j |  |  j j |  j j k r|  j j |  j j k r| j d  } | j d t |  j j d   | j d |  j j d  |  j j d  k	 r | j d  } | j d |  j j  | j |  n  |  j j
 |  j j
 k r| j |  j j
 j |   np | j d  } | j |  j j
 j |   | j |  | j d	  } | j |  j j
 j |   | j |  x' |  j D] } | j | j |   qW| j |  nj | j d  } | j |  j j |   | j |  | j d	  } | j |  j j |   | j |  | S(
   Nu   portdiffu   portu   portidi    u   protocoli   u   stateu   au   b(   R6   R7   R9   R   RQ   R   R?   R8   Rb   R   R   Re   R   (	   R   R:   R;   t   portdiff_elemt	   port_elemR   R   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe     sB     (   R   R	   R
   R   R   R   Re   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s
   			R   c           B   s8   e  Z d    Z d   Z e e  Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ d S(   s!   One of sr_a and sr_b may be None.N(   t   sr_at   sr_b(   R   R  R  (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    	c         C   s  g  } d } d } x | t  |   k  r| t  |  k  r|  | j | | j k  rz | j t |  | d   | d 7} q |  | j | | j k r | j t d | |   | d 7} q |  | j | | j k s t r | j t |  | | |   n  | d 7} | d 7} q Wx: | t  |   k  rP| j t |  | d   | d 7} qWx: | t  |  k  r| j t d | |   | d 7} qTW| S(   sR   Return a list of ScriptResultDiffs from two sorted lists of
        ScriptResults.i    i   N(   RF   RI   RT   R   R   R   R   (   RL   R   t   diffsR   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s*    ' !
c         C   st  g  } g  } |  j  d  k	 r- |  j  j   } n  |  j d  k	 rN |  j j   } n  | | k s` t rpt j d  | |  } x | j   D] \ } } } } }	 | d k s | d k r x/ t | |  D] }
 | j	 d | |
  q Wn  | d k s | d k r+x/ t | |	  D] }
 | j	 d | |
  q	Wn  | d k r x/ t | |  D] }
 | j	 d | |
  qGWq q Wn  d  S(   NR   R   u   -R   u   +R   u    (
   R  R   R   R  R   R   R   R   R   t
   append_raw(   R   R   t   a_linest   b_linesR	  R   R   R   R   R   t   k(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   4  s$    "c         C   s   | j    } |  j d  k	 rX |  j d  k	 rX |  j |  j k rX | j |  j j |   n |  j d  k	 r | j d  } | j |  j j |   | j |  n  |  j d  k	 r | j d  } | j |  j j |   | j |  n  | S(   Nu   au   b(   R6   R  R   R  R9   Re   R7   (   R   R:   R;   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRe   H  s    (   R   R	   R   R   R   R   Re   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s
   			R   c           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s0   A table of character data, like NmapOutputTable.c         C   s   g  |  _  g  |  _ d |  _ g  |  _ d } x0 | t |  k  r\ | | d k r\ | d 7} q- W| |  |  _ | d 7} | } xp | t |  k  r x0 | t |  k  r | | d k r | d 7} q W|  j j | | | ! | d 7} | } q} Wd S(   s   template is a string consisting of "*" and other characters. Each
        "*" is a left-justified space-padded field. All other characters are
        copied to the output.u    i    t   *i   N(   t   widthst   rowst   prefixt   paddingRF   RT   (   R   t   templateR   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   \  s     				%
%
c         C   s	  g  } t  |  } x0 t |  d k rD | d d  k rD | j   q Wx t t |   D] } | | d  k rw d } n t | |  } | t |  j  k r |  j j t |   n/ t |  |  j | k r t |  |  j | <n  | j |  qX W|  j j |  d  S(   Ni    iu    (	   R^   RF   R   t   popR   RG   R  RT   R  (   R   t   rowt   stringsR   RJ   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRT   q  s    %	c         C   s   |  j  j |  d S(   sA   Append a raw string for a row that is not formatted into columns.N(   R  RT   (   R   RJ   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR
    s    c         C   s   t  |  j  S(   N(   RF   R  (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   __len__  s    c         C   s   g  } x |  j  D] } |  j g } d } t | t  rG | j |  q xm | t |  k  r | j | | j |  j |   | t |  j  k  r | j |  j |  n  | d 7} qJ W| j d j	 |  j
    q Wd j	 |  S(   Ni    i   u    u   
(   R  R  t
   isinstancet
   basestringRT   RF   t   ljustR  R  RM   t   rstrip(   R   R   R  R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyRw     s    ! (   R   R	   R
   R   RT   R
  R  Rw   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR   Z  s   				c         C   s   t  j |  IJd S(   s   Print a warning to stderr.N(   R   t   stderr(   RG   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   warn  s    R   c           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   The xml.sax ContentHandler for the XML parser. It contains a Scan object
    that is filled in and can be read back again once the parse method is
    finished.c         C   s   | |  _  g  |  _ d  |  _ d  |  _ i |  j d 6|  j d 6|  j d 6|  j d 6|  j	 d 6|  j
 d 6|  j d 6|  j d 6|  j d	 6|  j d
 6|  j d 6|  j d 6|  _ i |  j d 6|  j d 6|  _ d  S(   Nu   nmaprunu   hostu   statusu   addressu   hostnameu
   extraportsu   portu   stateu   serviceu   scriptu   osmatchu   finished(   R   t   element_stackR   t   current_hostt   current_portt   _start_nmaprunt   _start_hostt   _start_statust   _start_addresst   _start_hostnamet   _start_extraportst   _start_portt   _start_statet   _start_servicet   _start_scriptt   _start_osmatcht   _start_finishedt   _start_elem_handlerst	   _end_hostt	   _end_portt   _end_elem_handlers(   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s(    				











c         C   s$   t  |  j  d k r d S|  j d S(   sg   Return the name of the element containing the current one, or None
        if this is the root element.i    iN(   RF   R  R   (   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   parent_element  s    c         C   sB   |  j  j |  } | d k	 r. | | |  n  |  j j |  d S(   s   This method keeps track of element_stack. The real parsing work is
        done in the _start_*() handlers. This is to make it easy for them to
        bail out on error.N(   R-  R   R   R  RT   (   R   R   R2   R%   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR0     s    c         C   s<   |  j  j   |  j j |  } | d k	 r8 | |  n  d S(   se   This method keeps track of element_stack. The real parsing work is
        done in _end_*() handlers.N(   R  R  R0  R   R   (   R   R   R%   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR4     s    c         C   s   |  j    d  k s t  d | k rT t | j d   } t j j |  |  j _ n  | j d  |  j _	 | j d  |  j _
 | j d  |  j _ d  S(   Nt   startu   startu   scanneru   argsu   version(   R1  R   t   AssertionErrort   intR   t   datetimet   fromtimestampR   R   R   R   R   (   R   R   R2   t   start_timestamp(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR!    s    	c         C   s>   |  j    d k s t  t   |  _ |  j j j |  j  d  S(   Nu   nmaprun(   R1  R3  R>   R  R   R   RT   (   R   R   R2   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR"    s    c         C   sy   |  j    d k s t  |  j d  k	 s- t  | j d  } | d  k ri t d | |  j j   f  d  S| |  j _ d  S(   Nu   hostu   stateuK   %s element of host %s is missing the "state" attribute; assuming \unknown\.(   R1  R3  R  R   R   R  RP   R?   (   R   R   R2   R?   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR#    s    c         C   s   |  j    d k s t  |  j d  k	 s- t  | j d  } | d  k ri t d | |  j j   f  d  S| j d d  } |  j j t j	 | |   d  S(   Nu   hostu   addru@   %s element of host %s is missing the "addr" attribute; skipping.u   addrtypeu   ipv4(
   R1  R3  R  R   R   R  RP   RV   Rn   R~   (   R   R   R2   Rh   t   addrtype(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR$    s    c         C   s}   |  j    d k s t  |  j d  k	 s- t  | j d  } | d  k ri t d | |  j j   f  d  S|  j j |  d  S(   Nu	   hostnamesu   nameu@   %s element of host %s is missing the "name" attribute; skipping.(   R1  R3  R  R   R   R  RP   RX   (   R   R   R2   RW   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR%    s    c         C   s@  |  j    d k s t  |  j d  k	 s- t  | j d  } | d  k rn t d | |  j j   f  d  } n  | |  j j k r t d | |  j j   f  n  | j d  } | d  k r t d | |  j j   f  d } nK y t |  } Wn8 t	 k
 r+t d | d |  j j   f  d } n X| |  j j | <d  S(	   Nu   portsu   stateuK   %s element of host %s is missing the "state" attribute; assuming "unknown".u+   Duplicate extraports state "%s" in host %s.u   countuC   %s element of host %s is missing the "count" attribute; assuming 0.i    uI   Can't convert extraports count "%s" to an integer in host %s; assuming 0.(
   R1  R3  R  R   R   R  RP   RC   R4  R|   (   R   R   R2   R?   R]   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR&    s,    		
c         C   s   |  j    d k s t  |  j d  k	 s- t  | j d  } | d  k ri t d | |  j j   f  d  Sy t |  } Wn/ t k
 r t d | |  j j   f  d  SX| j d  } | d  k r t d | |  j j   f  d  St	 | | f  |  _
 d  S(   Nu   portsu   portidu?   %s element of host %s missing the "portid" attribute; skipping.uB   Can't convert portid "%s" to an integer in host %s; skipping port.u   protocoluA   %s element of host %s missing the "protocol" attribute; skipping.(   R1  R3  R  R   R   R  RP   R4  R|   R   R   (   R   R   R2   t
   portid_strt   portidt   protocol(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR'  *  s&    c         C   s   |  j    d k s t  |  j d  k	 s- t  |  j d  k r@ d  Sd | k rm t d | |  j j   f  d  S| d |  j _ |  j j |  j  d  S(   Nu   portR?   uK   %s element of port %s is missing the "state" attribute; assuming "unknown".u   state(	   R1  R3  R  R   R   R  R   R?   RS   (   R   R   R2   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR(  B  s    c         C   s   |  j    d k s t  |  j d  k	 s- t  |  j d  k r@ d  S| j d  |  j j _ | j d  |  j j _ | j d  |  j j _	 | j d  |  j j _
 | j d  |  j j _ d  S(   Nu   portu   nameu   productu   versionu	   extrainfou   tunnel(   R1  R3  R  R   R   R   R   R   R   R   R   R   (   R   R   R2   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR)  O  s    c         C   s%  t    } | j d  | _ | j d  k r< t d |  d  S| j d  | _ | j d  k ro t d |  d  S|  j   d k r |  j j j	 |  n |  j   d k r |  j j
 j	 |  nb |  j   d k r |  j j j	 |  n: |  j   d k r|  j j j	 |  n t d	 |  d  Sd  S(
   Nu   idu0   %s element missing the "id" attribute; skipping.u   outputu4   %s element missing the "output" attribute; skipping.u	   prescriptu
   postscriptu
   hostscriptu   portuS   %s element not inside prescript, postscript, hostscript, or port element; ignoring.(   R   R   RI   R   R  R   R1  R   R   RT   R   R  RE   R   (   R   R   R2   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR*  Z  s*    	c         C   su   |  j    d k s t  |  j d  k	 s- t  d | k rZ t d | |  j j   f  d  S|  j j j | d  d  S(   Nu   osR   u@   %s element of host %s is missing the "name" attribute; skipping.u   name(   R1  R3  R  R   R  RP   RD   RT   (   R   R   R2   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR+  s  s    c         C   sX   |  j    d k s t  d | k rT t | j d   } t j j |  |  j _ n  d  S(   Nu   runstatsR,   u   time(   R1  R3  R4  R   R5  R6  R   R   (   R   R   R2   t   end_timestamp(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR,  }  s    c         C   s   |  j  j j   d  |  _  d  S(   N(   R  RE   R   R   (   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR.    s    c         C   s   |  j  j j   d  |  _  d  S(   N(   R   RE   R   R   (   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR/    s    (   R   R	   R
   R   R1  R0   R4   R!  R"  R#  R$  R%  R&  R'  R(  R)  R*  R+  R,  R.  R/  (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s&   						
										
		R   c           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s)   t  j j j j |  | d  | |  _ d  S(   Ns   utf-8(   R   R   t   saxutilst   XMLGeneratorR   R#   (   R   R#   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    c         C   s.   x' | j  D] } | j |  j d d q
 Wd  S(   Nt   newlu   
(   t
   childNodest   writexmlR#   (   R   R;   t   node(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR;     s    c         C   sK   |  j  d i   x' | j D] } | j |  j d d q W|  j d  d  S(   Nu   aR?  u   
(   R0   R@  RA  R#   R4   (   R   R;   RB  (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    c         C   sK   |  j  d i   x' | j D] } | j |  j d d q W|  j d  d  S(   Nu   bR?  u   
(   R0   R@  RA  R#   R4   (   R   R;   RB  (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s    (   R   R	   R   R;   R   R   (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyR     s   			c           C   s   d t  j d GHd  S(   Nu  Usage: %s [option] FILE1 FILE2
Compare two Nmap XML files and display a list of their differences.
Differences include host state changes, port state changes, and changes to
service and OS detection.

  -h, --help     display this help
  -v, --verbose  also show hosts and ports that haven't changed.
  --text         display output in text format (default)
  --xml          display output in XML formati    (   R   t   argv(    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   usage  s    i    i   i   c         C   sG   t  j d t  j d |  f IJt  j d t  j d IJt  j t  d  S(   Nu   %s: %si    u   Try '%s -h' for help.(   R   R  RC  t   exitt
   EXIT_ERROR(   t   msg(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   usage_error  s    c          C   sK  d  }  y2 t j t j d d d d d d g  \ } } Wn# t j k
 r] } t | j  n Xx | D] \ } } | d k s | d k r t   t j	 d	  qe | d
 k s | d k r t
 a qe | d k r |  d  k	 r |  d k r t d  n  d }  qe | d k re |  d  k	 r,|  d k r,t d  n  d }  qe qe Wt |  d k rXt d  n  |  d  k rmd }  n  | d	 } | d } y0 t   } | j |  t   }	 |	 j |  Wn7 t k
 r} t j d t |  IJt j	 t  n X|  d k r	t | |	  }
 n |  d k r't | |	  }
 n  |
 j   } | d	 k rCt St Sd  S(   Ni   t   hvt   helpt   textR   R   s   -hs   --helpi    s   -vs	   --verboses   --textu$   contradictory output format options.s   --xmli   u!   need exactly two input filenames.u   Can't open file: %s(   R   t   getoptt
   gnu_getoptR   RC  t   GetoptErrorRH  RG  RD  RE  R\   R   RF   R   R+   t   IOErrorR  RG   RF  R   R   R   t
   EXIT_EQUALt   EXIT_DIFFERENT(   t   output_formatt   optst   input_filenamest   et   oRL   t
   filename_at
   filename_bR   R   R   R   (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   main  sT    ,			

		c         C   s$   t  j |  | |  t  j t  d  S(   N(   R   t   __excepthook__RE  RF  (   R}   t   valuet   tb(    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt
   excepthook  s    t   __main__(8   R5  R   RL  R   R,   R   t   __path__R   t   xml.saxt   xml.sax.saxutilst   xml.dom.minidomR   R   R   R   R   R%   t   EntityResolverR   t   objectR   R>   Rn   Ry   Rz   R{   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  t   ContentHandlerR   R=  R>  R   RD  RP  RQ  RF  RH  RY  R]  R   RE  (    (    (    s)   /usr/lib/python2.7/dist-packages/ndiff.pyt   <module>   s^   +	E-+A$			(= [JD				8		