3
@6^                 @   s4   d dl mZ d dlmZmZmZ G dd deZdS )    )	IPAddress)
SpiderFootSpiderFootPluginSpiderFootEventc               @   s`   e Zd ZdZdddZdddZdZdZdZe	 fd	d
Z
dd Zdd Zdd ZdddZdS )sfp_dnsneighborzDNS Look-aside:Footprint,Investigate:DNS::Attempt to reverse-resolve the IP addresses next to your target to see if they are related.
   T)lookasidecountvalidatereversezyValidate that reverse-resolved hostnames still resolve back to that IP before considering them as aliases of your target.zOIf look-aside is enabled, the number of IPs on each 'side' of the IP to look up)r	   r   Nc             C   sR   || _ | j | _| j | _| j | _d| _x"t|j D ]}|| | j|< q8W d S )NDNS)	sftempStorageevents
domresultshostresults__dataSource__listkeysopts)selfsfcuserOptsopt r   :/var/www/spiderfoot.crq.systems/modules/sfp_dnsneighbor.pysetup$   s    


zsfp_dnsneighbor.setupc             C   s   dgS )N
IP_ADDRESSr   )r   r   r   r   watchedEvents/   s    zsfp_dnsneighbor.watchedEventsc             C   s   ddgS )NAFFILIATE_IPADDRr   r   )r   r   r   r   producedEvents5   s    zsfp_dnsneighbor.producedEventsc          !   C   s  |j }|j}|j}| jj|}d }|}| jjd| d |  || jkrLd S d| j|< yt|}W n2 tk
r }	 z| jj	d| d d S d }	~	X nX y0tt
|| jd  }
tt
|| jd  }W n4 tk
 r }	 z| jj	d| d d S d }	~	X nX | jjdt| d	 t|
  t
|
}t
|}x^||krtt|}| jjd
|  | j rdd S || jksz||kr|d7 }q0| jj|}|s| jjd| d  |d7 }q0| j j|rd}n(d}x"|D ]}| j j|rd}qW d| j|< | j|||}xp|D ]h}| j r&d S ||kr4q| jj|rH|}n|}| j j|rl| j||d n| j||d qW |d7 }q0W d S )NzReceived event, z, from TzInvalid IP address received: Fr   z Received an invalid IP address: zLookaside max: z, min: z!Attempting look-aside lookup of:    zLook-aside resolve for z failed.)	eventTypemoduledatar   
hashstringdebugr   r   BaseExceptionerrorintr   strcheckForStopr   	resolveIP	getTargetmatchesprocessHostvalidIP)r   event	eventNamesrcModuleName	eventDataeventDataHashaddrsparentEventipeZminipZmaxipscsipaffilaevaddrparentr   r   r   handleEvent9   sr    

 






zsfp_dnsneighbor.handleEventc       
      C   s0  | j j|j}|| jkr&|g| j|< nF|| j| ks>|j|krV| j jd| d  d S | j| |g | j|< | j jd|  |d krd}| j j|rd}| j j|s| j j|}|rx$|D ]}| j j|rd}qW n|}d }|r| j j|rd}n| j j|rd}|sd S t	||| j
|}	| j|	 |	S )NzSkipping host, z, already processed.zFound host: TFr   r   )r   r#   r"   r   r$   r+   r,   r.   resolveHostr   __name__notifyListeners)
r   hostr5   Z	affiliateZ
parentHashr;   ZhostipshostipZhtypeevtr   r   r   r-      s<    



zsfp_dnsneighbor.processHost)N)rB   
__module____qualname____doc__r   optdescsr   r   r   dictr   r   r   r@   r-   r   r   r   r   r      s   Tr   N)netaddrr   sflibr   r   r   r   r   r   r   r   <module>   s   