
Gc        T   @   s\  d  d k  l Z d  d k Z d Z e i i e i d d  Z y e i e  Wn e	 j
 o e
 Z n Xd   Z d e f d     YZ d  d k Z d  d k Z d  d k Z d	 e i f d
     YZ e i d  Z e i   Z e i e i d   e i e  e i d  Z e i e    e i d  Z e i d  Z e d j o e i d  n d  d k  Z  d  d k! Z! d  d k" Z" d  d k# Z# d  d k$ Z$ d  d k% Z% d  d k& Z& d  d k' Z' d  d k( Z( d  d k) Z) d  d k* Z* d  d k+ Z+ d  d k, Z, d  d k- Z- d  d k. Z. d  d k/ l0 Z0 d  d k1 l1 Z1 d  d k2 l2 Z2 d  d k3 l4 Z4 d  d k5 Z5 d  d k3 Z3 d  d k6 Z6 e6 i7 d d e8 e  y d  d k9 Z9 d Z: Wn& e; j
 o e i< d  d Z: n Xy d  d k= Z= d Z> Wn& e; j
 o e i< d  d Z> n Xe! i? i@ d  ZA e! i? i@ d  ZB e! i? i@ d  ZC e! i? i@ d  ZD e$ iE d d  d  j ZF e iG   d! d" j ZH e! i? i@ d#  ZI eA o d ZJ ZK n d ZJ ZK eK ou y d  d kL ZL d ZK WnX e; j
 oL eA o e iM d$  d ZK n( e d j o e iN d%  eO  n   n Xn eJ ou y d  d kP ZP d ZJ WnX e; j
 oL eA o e iM d&  d ZJ n( e d j o e iN d'  eO  n   n Xn eK oJ e iQ d(  ZR eR iS   d) ?d* j o e iM d+  d ZT n d ZT [R n y d  d, kU lV ZV Wn  e; j
 o e i< d-  n Xy e  iW d.  Wn e  iN j
 o d/   ZW n Xe  iW ZW e  iX ZX y e  iY ZY e  iZ ZZ Wn  e[ j
 o e i< d0  n XeI o d1 e  _\ n d2   Z] d3 e f d4     YZ^ d5 f  d6     YZ_ d7 d8 Z` d9 d8 Za d: Zb d; Zc d< Zd d Ze d= Zf d> Zg d? Zh d@ Zi dA Zj dB Zk dC Zl dD Zm dE Zn dF Zo dG Zp dH Zq dI Zr dJ Zs dK Zt d Zu dL Zv d! Zw d) Zx dM Zy dN Zz dO Z{ dP Z| dQ Z} d Z~ dL Z d: Z dR Z d8 Z d Z d Z dL Z dS Z dT Z d Z d Z d> Z dU Z dV Z dW   Z e dX  Z dY   Z e dZ  Z d[   Z e d\  \ Z Z d] e_ f d^     YZ d_   Z e d`  Z da   Z db   Z dc   Z dd   Z d d de  Z df   Z d d dg  Z dh   Z e- i Z eF o di   Z n
 dj   Z dk   ZM dl   Z dm   Z dn   Z do   Z dp   Z dq   Z e
 dr e
 e
 e
 e
 ds  Z h  dt du <dv dw <dx dy <dz d{ <d| d} <d~ d <d d <d d <d d <d d <d d <d d <d d <d d <Z d   Z d   Z d d d  Z d f  d     YZ d e f d     YZ e
 d  d  Z d   Z d   Z d   Z e
 d  Z d   Z d   Z d   Z d f  d     YZ d f  d     YZ d f  d     YZ eJ o d   Z d   Z n d   Z d   Z eK o+ d   Z d   Z d   Z d d  Z n( d   Z d   Z d   Z d d  Z eA o d   Z d   Z d   Z n% d   Z d   Z d   Z d   Z d   Z d   Z d Z h  Z d o eJ o eP i   Z d d  Z n d d  Z e
 d d d  Z d 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 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 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
 d  Z d e
 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e f d    YZ df  d    YZ de f d    YZ d	e f d
    YZ df  d    YZ de f d    YZ de f d    YZ d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%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 d0    YZd1e f d2    YZd3e f d4    YZ	d5e	f d6    YZ
d7e f d8    YZd9e f d:    YZd;e f d<    YZd=ee f d>    YZd d? Zd@  Zd dA ZdB  ZdCe f dD    YZdEf  dF    YZe iie dGef dH    YZdIef dJ    YZdKef dL    YZdMef dN    YZdOef dP    YZdQef dR    YZdSef dT    YZdUef dV    YZdWef dX    YZdYef dZ    YZ d[ef d\    YZ!d]ef d^    YZ"d_e"f d`    YZ#daef db    YZ$e, i%dc Z&e, i%dd Z'e, i%dee, i( Z)e, i%df Z*e, i%dg Z+dhe_ f di    YZ,dj  Z-dk  Z.dle/f dm    YZ0dne0f do    YZ1dpe0f dq    YZ2dre0f ds    YZ3dtf  du    YZ4dve4f dw    YZ5dxe4f dy    YZ6dze6f d{    YZ7d|f  d}    YZ8d~e8f d    YZ9de8f d    YZ:de8f d    YZ;de8f d    YZ<de6f d    YZ=df  d    YZ>df  d    YZ?df  d    YZ@df  d    YZAdf  d    YZBde>f d    YZCdeCf d    YZDdeCf d    YZEdeCf d    YZFdeCf d    YZGdeGf d    YZHdeGf d    YZIdeGf d    YZJde>f d    YZKdeKf d    YZLde>f d    YZMdeMf d    YZNdeNf d    YZOde>f d    YZPde>f d    YZQdePf d    YZRde>f d    YZSde>f d    YZTde>f d    YZUde>f d    YZVdeSf d    YZWde>f d    YZXdeXf d    YZYde>f d    YZZde>f d    YZ[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    YZadeaf d    YZbde]f d    YZcde>f d    YZdde>f d    YZeh  d h  d d<dL d<d: d<d! d<dR d<d8 d<dd<d) d<d f d<dL h  d d<dL d<d: d<d! d<dR d<d8 d<d f d<d: h  d d<dL d<d: d<d! d<dR d<d8 d<dd<d) d<dd<dd<dd<dd<dd<dd<dd<dd<d d<dd<dd<dd<dd	<d
d<d f d<d! h  d d<dL d<d: d<d! d<dR d<dd<dd<dM d<dd<dd<d f d<dR h  d d<dL d<d: d<d f d<d8 h  d f d <dh  d f d!<d) h  d f d"<d#h  d f d$<d%h  d f d&<d'h  d d(<dL d)<d f d*<d+h  d f d,<d-h  d f d.<dh  d f d/<dh  d f d0<dM h  d f d1<ZfefZgh  Zhx` egD]X ZiegeiZjh  Zkx$ ejd D] Zlelekejd el<qWeiekejdL f ehejd <qW[i[l[k[jd2ecf d3    YZmd4e]f d5    YZnd6e]f d7    YZod8e>f d9    YZpd:e>f d;    YZqd<e>f d=    YZrd>erf d?    YZsd@erf dA    YZtdBe>f dC    YZudDeuf dE    YZvdFereuf dG    YZwdHeuf dI    YZxdJeuf dK    YZydLeuf dM    YZzdNeuf dO    YZ{dPeuf dQ    YZ|dReuf dS    YZ}dTexf dU    YZ~dVe>f dW    YZdXeef dY    YZdZerf d[    YZd\e]f d]    YZh  d^e
 f d <d_e
 f d <d`daf dL <dbdcf d: <dde
 f d! <dedff dR <dgdhf d) <didjf d<dke
 f d<h  d d^<d d_<dL d`<d: db<d! dd<dR de<d) dg<ddi<ddk<f Zdle]f dm    YZdne]f do    YZdpePf dq    YZdr  Zdse]f dt    YZduef dv    YZdwecf dx    YZdye>f dz    YZd{Zd|erf d}    YZd~eSf d    YZderf d    YZdeQf d    YZde f d    YZd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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e0f d    YZdef d    YZde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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e f d    YZdef d    YZdef d    YZh  dd <dd: <dd! <ddR <dd) <dd#<dd%<dd'<dd+<dd-<dd<dd<ddM <dd<d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ef d    YZh  dd <dd: <ddR <dd<dd<dd<dd<dd<d d<dd<dd1 <dd<dd<d	d
<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd <d!d"<d#d$<d%d&<d'd(<d)d*<d+d,<d-d.<d/d0<d1d2<d3d4<d5d6<d7d8<d9d:<d;d<<d=d><d?d@<dAdB<dCd* <dDdE<dDdF<dGdH<dIdJ<dKdL<dMdN<dOdP<dQdR<dSdT<dUdV<dWdX<dYdZ<d[d\<d]d^<d_d`<d_da<dbdc<ddde<dfdg<dhdi<djdk<dldm<dndo<dpdq<drds<dtdu<dvdw<dxdy<dzd{<d|d}<d~d<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<d=d<dd<dDd<dDd<dd<dd<dd<dd<dd<dd<dYd<dd<dd<dd<dd<dd<dd<dpd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd <dd<dd<dd<dd<d	d
<Zdef d    YZdef d    YZdef d    YZh  dd <ddL <dd: <dd! <ddR <dd8 <dd<dd) <dd#<dd%<dd'<dd<dd<Zdef d    YZh  d d <d!dL <d"d: <d#d! <d$dE<d%d&<d'dF<d(d)<Zd*ef d+    YZd,ef d-    YZd.ef d/    YZd0ef d1    YZd2ef d3    YZd4ef d5    YZd6ef d7    YZd8ef d9    YZd:ef d;    YZh  d<d <d=d <Zd>ef d?    YZd@ef dA    YZdBef dC    YZdDef dE    YZdFef dG    YZdHef dI    YZh  dJd <dKdP<dLd <dMdL <dNd: <dNd! <dOdR <dPd8 <dQd<dRd) <dSd#<dTd%<dUd'<dVd+<dWd-<dXd<dYd<dZdM <d[d<d\d<d]d^<d_d<d`da<dbd<Zh  dcdL<ddde<dfdN<dgdh<dKdP<Zeie h  did <djdL <dkd: <dld! <dJdP<Zdmef dn    YZdoef dp    YZdqZdref ds    YZh  dtd <dudL <dvd: <dwd! <dxdR <dyd8 <dzd<d{d) <d|d#<d}d%<d~d'<dd+<dd-<Zh  dd <eKdd d <ddL <eKdd d: <eKdd d! <eKdd dR <eKdd d8 <eKdd d<eKdd d) <eKdd d#<dd+<dd<dd<dd<dd<dd= <dd<eKdd d^<dd<dd<dd<dda<dd<dd<eKdd d<eKdd d<dd<eKdd d<eKdd d<eKdd d<eSdd d<eKdd d<dd<ePdd d<eSdd d<eSdd d<dd<dd<ddO <eKdd d<eKdd d<eKdd d<eKdd d<eKdd d<eKdd d<eKdd d<eKdd d <dd<dd<ezdd e d
<ddP<Zh  ZxV ei  D]H \ ZZe e ej o eZie
 Zn
 eiZieef eei<q/W[i[[de]f d    YZdef d    YZdef d    YZdef d    YZddddddddddddddddg Zh  dd <dd <ddL <dd: <dd! <ddR <dd8 <dd<dd) <dd#<Zh  dd <dd <dd%<dd'<dd+<dd-<dd<dd<ddM <dd<d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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ef d    YZ def d    YZdef d    YZdef d    YZdddddd d!d"dd#d$d%d&d'g Zdd(d)d*d+d,g Zd-ef d.    YZd/ef d0    YZd1ef d2    YZd3ef d4    YZ	d5ef d6    YZ
d7ef d8    YZd9ef d:    YZd;ef d<    YZd=ef d>    YZd?ef d@    YZdAef dB    YZh  ZxV eee  D]B ZdCeeZee  j o h  edD<ee  e<n qP4W[[ei(   e_h  dEd <dFd <dGdL <dHd: <dId! <dJdR <dKd8 <dLd<dMd) <dNd#<dOd%<dPd'<dQd+<dRd-<dSd<dTd<dUdM <dVd<dWd<dXdN <dYd<dZd[<d\d<d]d<d^d<d_da<d`d<dad<dbd<dcd<ddd<ded<dfd<dgdh<did1 <djdk<dld<dmd<dnd<dodp<dqd
<drd<dsd<dtdu<dvd<dwdO <dxd<dydE<dzd&<d{dF<d|d}<d~d<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<ddQ <dd<dd<dd<dd<dd<dd<ddS <dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<d d<dd<dd<dd<dd	<d
d<dd<dd<dd<dd<dd<dd<dd<dd<dd<Zdef d    YZh  d d <d!d: <d"d! <d#dR <d#d8 <d$d<d%d) <d&d#<d'd%<d'd'<d(d+<d)d-<d*d<d+d<d#dM <d#d<d,d<d-d.<d/dT <d0d^<d1d2<d3dN <d4d<d5d[<Zd6ef d7    YZd8ef d9    YZd:ef d;    YZd<ef d=    YZd>ef d?    YZd@ef dA    YZdBef dC    YZ dDef dE    YZ!dFef dG    YZ"dHef dI    YZ#dJef dK    YZ$dLef dM    YZ%dNef dO    YZ&dPef dQ    YZ'dRef dS    YZ(dTef dU    YZ)dVef dW    YZ*dXef dY    YZ+dZef d[    YZ,d\ef d]    YZ-d^ef d_    YZ.d`ef da    YZ/dbef dc    YZ0ddef de    YZ1dfef dg    YZ2dhef di    YZ3djef dk    YZ4dlef dm    YZ5dnef do    YZ6dpef dq    YZ7dref ds    YZ8dtef du    YZ9dvef dw    YZ:dxef dy    YZ;dz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    YZAdef d    YZBdef d    YZCdef d    YZDdef d    YZEdef d    YZFdef d    YZGdef d    YZHdef d    YZIdef d    YZJdef d    YZKdef d    YZLdef d    YZMdef d    YZNdef d    YZOh  dd <ddL <dd: <dd! <ddR <dd8 <ZPdef d    YZQdef d    YZRdef d    YZSdef d    YZTdef d    YZUdef d    YZVdef d    YZWh  dd <dd <ddL <dd: <dd! <ddR <dd8 <dd<dd) <ZXdef d    YZYdef d    YZZ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    YZade	f d    YZbde	f d    YZcde"f d    YZdde"f d    YZede"f d    YZfde"f d    YZgde"f d    YZhde"f d    YZide"f d    YZjde"f d    YZkdef d    YZldef d    YZmdef d    YZndef d    YZodef d    YZpdef d    YZqdef d    YZrdef d    YZsh  dd <dd <ddL <dd: <dd! <ddR <dd8 <dd<dd) <dd#<dd%<d d'<dd+<dd-<dd<dd<ddM <dd<dd<Zth  dd <d	d <d
dL <dd: <dd! <ddR <dd8 <Zudef d    YZvdef d    YZwdef d    YZxdef d    YZydef d    YZz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+e	f d,    YZd-e"f d.    YZd/e"f d0    YZd1e"f d2    YZd3e"f d4    YZd5ef d6    YZd7ef d8    YZd9ef d:    YZd;ef d<    YZd=ef d>    YZd?ef d@    YZdAef dB    YZe
 dC Ze
 dD Ze
 dE Ze
 dF Ze
 dG Ze
 dH Zeee ee"e eee eee eeedIdL eee eee eee eeedJdeeedJdeeedJdeeedIdKeeedIdLeeedId eeedId< eeedId; eeedIdMeeedNdOdIdMeeedIdPeeedIdQeeedJdKeeedJdLeeedJd eeedJd< eeedJd; eeedJdMeeedJdPeeedJdQee edJdKee edJdLee edJd ee edJd< ee edJd; ee edJdMeeedRd eeedId eeedSddTddUd: eeedSdVdTdVdUd: eeedRdLeeedRd eeedRd< eeedRd; eeedRdMeeedRdWeeedXd dJd! eeedXd dJd eeedXd dJd8 eeedXd dJdeeedXd dJd! eeedXd dJd eeedXd dJd8 eeedXd dJdeee dXd dJd1 eeedYdZd[dZeeedYd\eeed[d\eee!d[d]eee!dYd]eeed[d
eeedYd
eeed[d^dYd^eeed[d_dYd_eeed[d`dYd`eeed[ddYdaeeed[dadYdeeedbdqeeedYdceeed[dceee eee eeeddd dId eeeddd dId eeedddL dId eeeddd: dId eeeddd! dId eeedddR dId eeeddd) dId eeeddd#dId eeeddd%dId eeeddd'dId eeeddd+dId eee eee eee eee eee eee eee eee eee eeed[deeeedYdeeeedYdfeeed[dfeeed[dfdYdfeeedgd eee dgdL dIdL eeedgdL eeedgd: dIdL eeedgd: eee1dJd= ee1e2dhd ee2e3 eee4d[deee5d[deee6dYdeee7dYdeee8dYdee8e9 ee8e9 ee9e9 ee9e: eee;dYdeee<d[deee=d[dee=eB eeBeC eeCeC ee=eDdid ee=eEdid djd) ee=eFdid djd ee=eG ee=eH ee#e$dIdL ee#e ee$e% ee%e&dkd ee&e)dRd ee&e'dRdL ee&e(dRd: ee&e*dRd! ee&e+dRdR ee&e,dRd8 ee&e-dRdee&e.dRd%ee&e/dRd'eeeIdYdleeeId[dleeIeJdId eeIeKdId: eeIeLdId! eeLedmd! eeMeNdgd eeNeO eeeQd[deeQeRdnd eeQeSdndL eeQeTdnd: eeQeWdnd! eeQeYdndR eeQeZdnd8 eeReV eeSeV eeZeV dodp Zd) e
 dq Zdr  Zds  Ze
 dt Zh  eee <eef <eeh <ed#<ed+<ed6<edu<edv<edw<ed:<ed><edx<ed* <ed<e1dy<e#dz<Zh  ee e<d#e<d+e<d6e<due<dve<dwe<d* e<d:e<d>e<de<dye1<Zh  eec <eed <eeb <Zd{  Zd|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ef d    YZdef d    YZdL d e
 d d d d Zd d e
 e
 d Zd d e
 e
 d Zd d e
 e
 e
 e
 d Ze
 e
 e
 d e
 d Ze
 e
 d d Ze
 e
 d d Ze
 e
 e
 d eb d Zd  Zd  d  d e
 e
 e
 d d Zd  Zd  Zd  d d d d Ze
 e
 e
 d Ze
 e
 e
 e
 d Zdd Zd  Zd  Zd  d Zdf  d    YZdf  d    YZe, i%d Zd  Zd  Zd  Zdf  d    YZdef d    YZdef d    YZd  Zdef d    YZd  Zd  Zd  Zd  Zdd Zd  Zdef d    YZdd: d Zd  Zd  Zdef d    YZd  Zd  Zd  Zd  Zdd&d d Zd  Zd  Zdd&d Zd  Zd d e
 e
 e
 e
 e
 d Zdd Zdd de   e
 e
 dL e
 d ZdL d e
 d ZdLd%d ZdKd%d Zdd ZdL dd Zd  Ze
 d Zddd Zd  Ze
 e
 e
 d Zd  Zd  Zd  Ze
 d Ze
 d Zeeeeeeeeeeeeeeeeeeeeeeg Zdf  d    YZde f d    YZd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ef d    YZdef d    YZd d Zd  Ze
 d	 Z e
 d
 Zd  Ze
 d Zd  d  d Ze
 Zd  Zd  Zd`d`dd d Zdd d Z	g  a
d  Zddd Zdf  d    YZd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/ef d0    YZd1ef d2    YZd3f  d4    YZd5f  d6    YZd7ef d8    YZd9f  d:    YZd;ef d<    YZe  Zei i dd=d d Z!e!d>j o e!e_"n [!eK o* ee_#eJ o ee_$ee_%n n eei& Z'eei( Z)eei* Z+eei, Z-eei. Z/d?e f d@    YZ0dAe& i1f dB    YZ2e
 d dC Z3dD  Z4dE  Z5dF  Z6dG  Z7dH  Z8dI  Z9e
 e
 e
 d dJ Z:dK  Z;e d j o e:  n e o e;e  n d S(L  i(   t
   generatorsNs   1.2.0.2t   HOMEs   .scapy_startup.pyc           C   s   d GHt  i d  d  S(   Ns\   Usage: scapy.py [-s sessionfile] [-c new_startup_file] [-C]
    -C: do not read startup filei    (   t   syst   exit(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   usage#   s    t   Scapy_Exceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   -   s   t   ScapyFreqFilterc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  i i |   h  |  _ d  S(   N(   t   loggingt   Filtert   __init__t   warning_table(   t   self(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   3   s    c         C   s   t  i } | d j o t i   } d  } x2 | D]* \ } } } } | d j o Pn | } q/ W|  i i | d  \ }	 }
 t i   } | |	 | j o | }	 d }
 nA |
 d j  o/ |
 d 7}
 |
 d j o d | i | _ q n d S|	 |
 f |  i | <n d S(   Ni    t   warningi   i   s   more (   i    i    (	   t   conft   warning_thresholdt	   tracebackt   extract_stackt   NoneR   t   gett   timet   msg(   R   t   recordt   wtt   stkt   callert   ft   lt   nt   ct   tmt   nbt   ltm(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   filter6   s*    	 


(   R   R   R   R"   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   2   s   	t   scapys   %(levelname)s: %(message)ss   scapy.runtimes   scapy.interactives   scapy.loadingt   __main__i   (   t   Set(   t   select(   t   glob(   t   ioctlt   ignoret   tempnams;   did not find python gnuplot wrapper . Won't be able to ploti    s<   Can't import PyX. Won't be able to use psdump() or pdfdump()t   linuxt   openbsdt   freebsdt   darwint   Ht    i   t   x86_64t   sunoss6   did not find pcap module. Fallback to linux primitivess   did not find pcap modules6   did not find dnet module. Fallback to linux primitivess   did not find dnet modules   tcpdump -V 2> /dev/nulli   i   s@   Failed to execute tcpdump. Check it is installed and in the PATH(   t   ARC4s:   Can't find Crypto python lib. Won't be able to decrypt WEPs   255.255.255.255c         C   s&   |  d j o d Sn t  i |   Sd  S(   Ns   255.255.255.255s   i   s   (   t   sockett	   inet_aton(   t   x(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR5      s    sC   inet_ntop/pton functions not found. Python IPv6 support not presenti/   c         C   s3   |  o |  d d j o d |  }  n |  i  d  S(   Ni    t
   0123456789t   n_t   ________________________________________________0123456789_______ABCDEFGHIJKLMNOPQRSTUVWXYZ______abcdefghijklmnopqrstuvwxyz_____________________________________________________________________________________________________________________________________(   t	   translate(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   fixname   s    t   DADict_Exceptionc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR<      s   t   DADictc           B   s   e  Z d  d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	 d
  Z
 d   Z d   Z d   Z d   Z d   Z d   Z RS(   R=   c         K   s   | |  _  |  i i |  d  S(   N(   t   _namet   __dict__t   update(   R   R>   t   kargs(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR      s    	c         C   s
   t  |  S(   N(   R;   (   R   t   val(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR;      s    c         C   s   | |  i  j S(   N(   R?   (   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __contains__   s    c         C   s   t  |  |  S(   N(   t   getattr(   R   t   attr(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __getitem__   s    c         C   s   t  |  |  i |  |  S(   N(   t   setattrR;   (   R   RE   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __setitem__   s    c         C   s+   t  t d   t d   |  i i      S(   Nc         S   s   |  \ } } | S(    (    (   t   .0R6   t   y(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   <lambda>   s    c         S   s!   |  \ } } | o | d  d j S(   i    t   _(    (   RI   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK      s    (   t   itert   mapR"   R?   t   items(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __iter__   s    c         C   sR   xK |  i  i   D]: } | o- | d d j o d | t |  |  f GHq q Wd  S(   Ni    RL   s	   %10s = %r(   R?   t   keysRD   (   R   t   k(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _show   s     c         C   s/   d |  i  d i t d   |  i i     f S(   Ns   <%s/ %s>t    c         S   s   |  o |  d  d j S(   i    RL   (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK      s    (   R>   t   joinR"   R?   RQ   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __repr__   s    i    c         C   sH   | o0 | i  |  j o  t d | i  |  i  f   n | |  | i  <d  S(   Ns%   DADict: [%s] already branched in [%s](   R>   R<   (   R   t   brt   uniq(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _branch   s     c         O   s^   | o |  i  | j o t Sn x8 | D]0 } | |  j p |  | | | j o t Sq& q& Wt S(   N(   R>   t   Falset   True(   R   t   argsRA   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _my_find   s     "c         O   s   |  i  d | |  S(   N(    (   t   _recurs_find(   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _find   s    c         O   s   |  | j o d  Sn |  i | |   o |  Sn xS |  D]K } t | t  o5 | i | |  f | |  } | d  j	 o | Sq q7 q7 Wd  S(   N(   R   R]   t
   isinstanceR=   R^   (   R   t   pathR\   RA   t   ot   p(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR^     s     c         O   s   |  i  d | |  S(   N(    (   t   _recurs_find_all(   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   _find_all  s    c         O   s   g  } |  | j o | Sn |  i  | |   o | i |   n xH |  D]@ } t | t  o* | i | |  f | |  } | | 7} qF qF W| S(   N(   R]   t   appendR`   R=   Rd   (   R   Ra   R\   RA   t   rRb   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRd     s     c         C   s   t  d   |  i i    S(   Nc         S   s   |  o |  d  d j S(   i    RL   (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   R"   R?   RQ   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRQ     s    (   R   R   R   R;   RC   RF   RH   RP   RS   RV   RY   R]   R_   R^   Re   Rd   RQ   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR=      s   												t    i   s   i   i   i  i   i   i  i  i'  i  i  i  i  i  i  i  i3  i8  i  i   i   i    i@   i   i   i   i  i   ipBi@  c         C   s0  t  i d  } t d |   } y x t |   D] } y | i d  } | d j o | |  } n | i   } | p w. n t t  i | |   } t |  d j  p | d o w. n t	 | d  | | d <Wq. t
 j
 o# } t i d |  | | f  q. Xq. WWn  t j
 o t i d  n X| S(	   Ns   [ 	]+|
R>   t   #i    i   i   s(   Couldn't parse file [%s]: line [%r] (%s)s   Can't open /etc/protocols file(   t   ret   compileR=   t   opent   findt   stript   tuplet   splitt   lent   intt	   Exceptiont   log_loadingt   infot   IOError(   t   filenamet   spacest   dctR   t   shrpt   ltt   e(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   load_protocolsi  s*     's   /etc/protocolsc   	      C   s8  t  i d  } t d |   } y t |   } x | D] } y | i d  } | d j o | |  } n | i   } | p w4 n t t  i | |   } t |  d j  p | d o w4 n t	 | d d  | | d <Wq4 t
 j
 o# } t i d |  | | f  q4 Xq4 W| i   Wn t j
 o	 } n X| S(	   Ns   [ 	]+|
R>   Ri   i    i   i   i   s(   Couldn't parse file [%s]: line [%r] (%s)(   Rj   Rk   R=   Rl   Rm   Rn   Ro   Rp   Rq   Rr   Rs   Rt   Ru   t   closeRv   (	   Rw   Rx   Ry   R   R   Rz   R{   R|   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   load_ethertypes  s.     #s   /etc/ethertypesc   	      C   s  t  i d  } t d d |   } t d d |   } y]t |   } x@| D]8} y | i d  } | d j o | |  } n | i   } | p wK n t t  i | |   } t |  d j  p | d o wK n | d i	 d	  o) t
 | d i d
  d  | | d <n> | d i	 d  o) t
 | d i d
  d  | | d <n WqK t j
 o# } t i d |  | | f  qK XqK W| i   Wn  t j
 o t i d  n X| | f S(   Ns   [ 	]+|
R>   s   %s-tcps   %s-udpRi   i    i   i   s   /tcpt   /s   /udps"   Couldn't file [%s]: line [%r] (%s)s   Can't open /etc/services file(   Rj   Rk   R=   Rl   Rm   Rn   Ro   Rp   Rq   t   endswithRr   Rs   Rt   R   R~   Rv   Ru   (	   Rw   Rx   t   tdctt   udctR   R   Rz   R{   R|   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   load_services  s6     )-#s   /etc/servicest   ManufDAc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   | S(   N(    (   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR;     s    c         C   s;   d i  | i d  d   i   } |  i i | | | f  S(   Nt   :i   (   RU   Rp   t   upperR?   R   (   R   t   mact   oui(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _get_manuf_couple  s    "c         C   s   |  i  |  d S(   Ni   (   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   _get_manuf  s    c         C   s   |  i  |  d S(   Ni    (   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _get_short_manuf  s    c         C   s`   d i  | i d  d   i   } | |  j o- d i  |  | d g | i d  d  Sn | S(   NR   i   i    (   RU   Rp   R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _resolve_MAC  s    "-(   R   R   R;   R   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
   				c         C   s   y t  d |   } x t |   D] } y | i   } | p | i d  o w n | i   d  \ } } | i d  } | d j  o
 | } n | | d } | | f | | <Wq t j
 o# } t i d |  | | f  q Xq WWn t	 j
 o n X| S(   NR>   Ri   i   i    s+   Couldn't parse one line from [%s] [%r] (%s)(
   R   Rl   Rn   t
   startswithRp   Rm   Rs   Rt   R   Rv   (   Rw   t   manufdbR   R   t   shrtt   it   lngR|   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   load_manuf  s&     
's$   /usr/share/wireshark/wireshark/manufc         C   se   d } xX |  D]P } t  |  } | d j  p | d j o | t i i d  } q | | } q W| S(   Nt    i    i   t   .(   t   ordR   t   color_themet   not_printable(   R6   Rg   R   t   j(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   sane_color  s     c         C   sY   d } xL |  D]D } t  |  } | d j  p | d j o | d } q | | } q W| S(   NR   i    i   R   (   R   (   R6   Rg   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   sane  s     c         C   s   t  |   t t f j o t |   Sng t  |   t j o d d i t t |    Sn6 t  |   t j o d d i t t |    Sn |  Sd  S(   Ns   (%s)s   , s   [%s](	   t   typeRr   t   longt   hexRo   RU   RN   t   lhext   list(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  |   }  t |   } d } x | | j  o d | Gx\ t d  D]N } | | | j  o d t |  | |  Gn d G| d d j o d GqC qC Wd Gt |  | | d ! GH| d 7} q! Wd  S(	   Ni    s   %04x  i   s   %02Xs     i   R   RT   (   t   strRq   t   rangeR   R   (   R6   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   hexdump	  s     c         C   sj   t  |   }  t |   } | p1 x& t |  D] } d t |  |  Gq, Wd Gn | p t |   GHn d  S(   Ns   %02XR   (   R   Rq   R   R   R   (   R6   t   onlyasct   onlyhexR   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   linehexdump  s     c         C   s*   t  |   }  d i t d   |    GHd  S(   Ns   , c         S   s   d  t  |   S(   s   %#04x(   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   &  s    (   R   RU   RN   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   chexdump$  s    c         C   s^   g  } | p& | i  d i t d   |     n | p | i  t |    n d i |  S(   NRT   c         S   s   d  t  |   S(   s   %02x(   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   +  s    s     (   Rf   RU   RN   R   (   R6   R   R   t   s(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   hexstr(  s    &c         C   s  t  |   d  d  d  }  t  |  d  d  d  } d } d } h  } d d f | d <xP t t |   D]< } | d | d f d | d | d f f | d | f <qg WxP t t |    D]< } | | d d f d | | d d f f | | d f <q Wx t t |   D] } x t t |    D] } t | | d | d f d | |  | | | j | d | d f f | | d | f d | | d | f f | | | d f d | | | d f f  | | | f <q&WqWg  } g  } t |   d } t |  d } x | | j o
 d j n pc | | | f d \ }	 }
 | i |  |	 d | d ! | i | |
 d | d ! |	 |
 } } qWd }  } } h  d   d <t i i d <t i i d <} d } d } t |  } x| | j  od } | | | d !} | | | d !} t	 d   | D  } t	 d   | D  } | o | o d } d } n | o | | j o
 d } n | o] | } d } x$ | | p | d 7} | d 8} qW| | | d |  G|  | 7}  | } n d	 G| o] | } d } x$ | | p | d 7} | d 8} qW| | | d |  G| | 7} | } n d	 Gd
 Gd } x t d  D] } | | | j  o | | o | | | | | j | | } | d t
 | |   G| | | | j o | t | |  7} q| | t | |   7} q&d G| d
 7} n d G| d j o d GqkqkWd
 G| GH| p | o d } d } | d 7} q| o d } d } q| d 7} qWd  S(   Nii   i    c         S   s   |  S(    (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   Q  s    i   c         s   s   x |  ] } t  |  Vq Wd  S(   N(   Rq   (   RI   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pys	   <genexpr>\  s    c         s   s   x |  ] } t  |  Vq Wd  S(   N(   Rq   (   RI   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pys	   <genexpr>]  s    s   %04xs       RT   R   s   %02Xs     i   (   ii(   ii(   R   R   Rq   t   minRf   R   R   t   leftt   rightt   sumR   R   R   (   R6   RJ   t   SUBSTt   INSERTt   dR   R   t
   backtrackxt
   backtrackyt   i2t   j2t   colorizet   doxt   doyR   t   separatet   linext   lineyt   xxt   yyt   xdt   linet   ydt   clt   col(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   hexdiff1  s     : :  F)A!







  	
c         C   sl   t  |   d d j o |  d 7}  n t t i d |    } | d ?| d @} | | d ?7} | } | d @S(   Ni   i   Rh   R/   i   i  (   Rq   R   t   array(   t   pktR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   checksum  s    c         C   s|   t  |   d d j o |  d 7}  n t t i d |    } | d ?| d @} | | d ?7} | } | d ?d @| d >Bd @S(	   Ni   i   Rh   R/   i   i  i   i   (   Rq   R   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  i |   d  S(   N(   t   log_runtimeR   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s"   d i  t d   |  i d    S(   NR   c         S   s   t  t |  d    S(   i   (   t   chrRr   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R   (   RU   RN   Rp   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   mac2str  s    c         C   s   d d d  t  t t |    S(   Ns   %02x:i   i(   Ro   RN   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   str2mac  s    c         C   s   d i  t d   |  |   S(   NR   c         S   s   t  t |   t |  A S(    (   R   R   (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   RU   RN   (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   strxor  s    c         C   sR   y t  |   } Wn+ t i j
 o t  t i |    } n Xt i d |  d S(   Ns   !Ii    (   R5   R4   t   errort   gethostbynamet   structt   unpack(   R6   t   ip(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   atol  s
    c         C   s   t  t i d |    S(   Ns   !I(   t	   inet_ntoaR   t   pack(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   ltoa  s    c         C   s   d |  ?d @S(   Nl        l    (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   itom  s    t   svgc   	      C   s   | o |  Sn | d j	 o
 | } n | d j o t i i } n | d j o d t i i } n | d j	 o d | } n t i d | | p d | p d | f  \ } } | i |   | i   d S(   s  do_graph(graph, prog=conf.prog.dot, format="svg",
         target="| conf.prog.display", options=None, [string=1]):
    string: if not None, simply return the graph string
    graph: GraphViz graph description
    format: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T" option
    target: filename or redirect. Defaults pipe to Imagemagick's display program
    prog: which graphviz program to use
    options: options to be passed to progs   | %ss   -T %ss   %s %s %s %sR   N(	   R   R   t   progt   dott   displayt   ost   popen2t   writeR~   (	   t   graphR   t   formatt   targetR   t   stringt   optionst   wRg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   do_graph  s    
3s   {\tt\char123}t   {s   {\tt\char125}t   }s   {\tt\char92}s   \s   \^{}t   ^s   \$t   $s   \#Ri   s   \~t   ~s   \_RL   s   \&t   &s   \%t   %s   {\tt\char124}t   |s   {\tt\char126}s   {\tt\char60}t   <s   {\tt\char62}t   >c         C   s1   d } x$ |  D] } | t  i | |  7} q W| S(   NR   (   t   _TEX_TRR   (   R6   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   tex_escape  s
     c       
   o   s	  t  |   d j  o |  d 9}  n | i d d    } x x t t  |    D] } x t t  |    D] } x t t  |    D]x } | | j p | | j p | | j oK | |  | | t  |   |  | | t  |   |  | | t  |    Vq~ q~ Wqe WqL Wq9 d S(   s   Returns a generator that mixes provided quantities forever
    trans: a function to convert the three arguments into a color. lambda x,y,z:(x,y,z) by defaulti   t   transc         S   s   |  | | f S(    (    (   R6   RJ   t   z(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK      s    N(   Rq   R   R   (   t   lstcolRA   R   R   R   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   colgen  s       's   tag%05ic         c   s&   x t  o |  | V| d 7} q Wd  S(   Ni   (   R[   (   t   labelt   start(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   incremental_label  s    
	t   EnumElementc           B   s;   e  Z d Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   _keyt   _value(   R   t   keyt   value(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   s,   d |  i  i d |  i i  |  i |  i f S(   Ns   <%s %s[%r]>R>   (   R?   R   t	   __class__R   R   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    c         C   s   t  |  i |  S(   N(   RD   R   (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __getattr__  s    c         C   s   |  i  S(   N(   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __str__  s    c         C   s   |  i  t |  j S(   N(   R   Rr   (   R   t   other(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __eq__  s    N(	   R   R   R   R   R   RV   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   				t   Enum_metaclassc           B   s>   e  Z e Z d    Z d   Z d   Z d d  Z d   Z	 RS(   c         C   s   h  } xW | i    D]I \ } } t |  t j o* |  i | |  } | | | <| | | <q q W| | d <t t |   i |  | | |  S(   Nt	   __rdict__(   t	   iteritemsR   Rr   t   element_classt   superR   t   __new__(   t   clst   namet   basesRy   t   rdictRR   t   v(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  "  s     

c         C   s   |  i  | S(   N(   R  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRF   +  s    c         C   s   | |  i  j S(   N(   R  (   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRC   -  s    c         C   s   |  i  i | |  S(   N(   t   _rdict__R   (   R   RE   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   /  s    c         C   s   d |  i  i d |  i  S(   Ns   <%s>R  (   R?   R   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   1  s    N(
   R   R   R   R  R  RF   RC   R   R   RV   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR      s   				c      	   C   s  | d  j o
 t } n | i   } | i d  o | d =n xi | i   D][ } t | |  t i t i t i	 g j o, t
 i d | t | |  f  | | =qK qK Wy t i |  |  d  Wn t j
 o n Xt i |  d  } t i | | |  | i   d  S(   Nt   __builtins__s   [%s] (%s) can't be saved.s   .bakt   wb(   R   t   scapy_sessiont   copyt   has_keyRQ   R   t   typest   TypeTypet	   ClassTypet
   ModuleTypet   log_interactiveR   R   t   renamet   OSErrort   gzipRl   t   cPicklet   dumpR~   (   t   fnamet   sessiont   pickleProtot   to_be_savedRR   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   save_session<  s"    
 )!c         C   sh   y t  i t i |  d   } Wn+ t j
 o t  i t |  d   } n Xt i   t i |  d  S(   Nt   rb(   R  t   loadR  Rl   Rv   R  t   clearR@   (   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   load_sessionR  s    
c         C   s^   y t  i t i |  d   } Wn+ t j
 o t  i t |  d   } n Xt i |  d  S(   NR   (   R  R!  R  Rl   Rv   R  R@   (   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   update_sessionZ  s
    c         C   s-   t  i t i i t i |  d  d   GHd  S(   Ni   i	   (   t   base64t   encodestringR  t   zlibt   compressR  t   dumps(   t   obj(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   export_objectb  s    c         C   sH   |  d  j o t i i   }  n t i t i i t	 i
 |  i      S(   N(   R   R   t   stdint   readR  t   loadsR  R'  t
   decompressR%  t   decodestringRn   (   R*  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   import_objecte  s    c         C   s    t  i | t i |  d   d  S(   NR  (   R  R  R  Rl   (   R  R*  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   save_objectk  s    c         C   s   t  i t i |  d   S(   NR   (   R  R!  R  Rl   (   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   load_objectn  s    c         C   s  d d  k  } t i } t |  t j	 o | g } n t i i t i i |    } t i i	 |  } t i i
 |  } | i d  o | d  } n | i d |  d  } } z t i   } t i |  t i } t i | 7_ y | i | |  } Wn$ t j
 o t i d |   n3 X| i | |  }	 d d  k }
 |
 i i |	 i  Wd  | o | t _ n | o t i |  n Xd  S(   Nis   .pyii    s4   Module [%s] not found. Check conf.extensions_paths ?(   t   impR   t   extensions_pathsR   R   R   Ra   t   realpatht
   expandusert   dirnamet   basenameR   t   insertR   t   getcwdt   chdirR   t   find_modulet   ImportErrorR   R   t   load_modulet   __builtin__R?   R@   (   Rw   R4  t   pathsR  t   thepatht   thenamet   cwdt   syspatht   extft   extR@  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   load_extensionw  s6    	

t   debugc           B   s   e  Z g  Z g  Z g  Z RS(    (   R   R   t   recvt   sentt   match(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRI    s   t   IPToolsc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s7   Add more powers to a class that have a "src" attribute.c         C   s   t  i d |  i  d  S(   Ns   whois %s(   R   t   systemt   src(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   whois  s    c         C   s>   d d d d g |  i  g } | i   | | i |  i   d S(   Ni    i@   i   i   i   (   t   ttlt   sortt   index(   R   t   t(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   ottl  s    
c         C   s   |  i    |  i d S(   Ni   (   RU  RQ  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   hops  s    (   R   R   t   __doc__RP  RU  RV  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRM    s   		t   Routec           B   s   e  Z d    Z d   Z d   Z d   Z d d d d d  Z d   Z d   Z	 d   Z
 d   Z d	   Z d d
  Z d   Z RS(   c         C   s2   |  i    t i t i t i  |  _ h  |  _ d  S(   N(   t   resyncR4   t   AF_INETt
   SOCK_DGRAMR   t   cache(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    
c         C   s   h  |  _  d  S(   N(   R\  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   invalidate_cache  s    c         C   s   |  i    t   |  _ d  S(   N(   R]  t   read_routest   routes(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRY    s    
c         C   sV   d } xI |  i  D]> \ } } } } } | d t |  t |  | | | f 7} q W| S(   NsJ   Network         Netmask         Gateway         Iface           Output IP
s   %-15s %-15s %-15s %-15s %-15s
(   R_  R   (   R   t   rtt   nett   mskt   gwt   ifacet   addr(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    
 	c   
      C   s   | d  j	 o | d } } n? | d  j	 o% | i d  \ } } t |  } n t d   | d  j o
 d } n | d  j o3 | o
 | } n | } |  i |  \ } } }	 n t |  } t |  t |  | | | f S(   Ni    R   sD   make_route: Incorrect parameters. You should specify a host or a nets   0.0.0.0(   R   Rp   Rr   R   t   routet   get_if_addrR   R   (
   R   t   hostRa  Rc  t   devt   thenetRb  t   nhopt   ifaddrR6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   make_route  s    

c         O   s*   |  i    |  i i |  i | |    d S(   s;   Ex:
        add(net="192.168.1.0/24",gw="1.2.3.4")
        N(   R]  R_  Rf   Rm  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   add  s    
c         O   s`   |  i    |  i | |   } y  |  i i |  } |  i | =Wn t j
 o t d  n Xd S(   s   delt(host|net, gw|dev)s   no matching route foundN(   R]  Rm  R_  RS  t
   ValueErrorR   (   R   R\   RA   Rf  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   delt  s    
c         C   s  |  i    | i d  d g d  \ } } t t |   } t |  } | | @} x t t |  i   D] } |  i | \ } }	 }
 } } | | j o qh n |
 d j o  | | |
 | | f |  i | <qh | |	 |
 | | f |  i | <qh Wx t i	   D] } t | =q Wd  S(   NR   t   32i   s   0.0.0.0(
   R]  Rp   R   Rr   R   R   Rq   R_  t	   arp_cacheRQ   (   R   t   iffRe  t   the_addrt   the_mskt   the_rawaddrt   the_netR   Ra  Rb  Rc  Rd  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   ifchange  s     
 
    c         C   sS   |  i    g  } x3 |  i D]( } | d | j o | i |  q q W| |  _ d  S(   Ni   (   R]  R_  Rf   (   R   Rs  t
   new_routesR`  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   ifdel
  s    

 c         C   su   |  i    | i d  d g d  \ } } t t |   } t |  } | | @} |  i i | | d | | f  d  S(   NR   Rq  i   s   0.0.0.0(   R]  Rp   R   Rr   R   R_  Rf   (   R   Rs  Re  Rt  Ru  Rv  Rw  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   ifadd  s    
 
c         C   s  | |  i  j o |  i  | Sn | d  j o t i } n | i d  d } | i d d  } xQ | i d  } | d j  o Pn | | d i d  } | |  | | | } qa t |  } g  } x |  i D] \ } } } }	 }
 t |
  } | | j o  | i	 d d |
 d	 f f  n | | @| | @j o  | i	 | |	 |
 | f f  q q W| p | o t
 d
  n d Sn | i   | d d } | |  i  | <| S(   NR   i    t   *t   0t   -R   l    t   los   0.0.0.0s"   No route found (no default route?)ii   (   R  s   0.0.0.0s   0.0.0.0(   R\  R   R   t   verbRp   t   replaceRm   R   R_  Rf   R   RR  (   R   t   destt   verboset   dstR   t   mt   pathesR   Rc  R   t   at   aat   ret(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRf    s:    
  $
c         C   sr   x] |  i  D]R \ } } } } } | | j o0 | d j o# t |  | d @B} t |  Sq
 q
 Wt d |  d  S(   Nl    l    s(   No broadcast address found for iface %s
(   R_  R   R   R   (   R   Rs  Ra  Rb  Rc  Rd  Re  t   bcast(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_if_bcast>  s    
 N(   R   R   R   R]  RY  RV   R   Rm  Rn  Rp  Rx  Rz  R{  Rf  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRX    s   				
		
				#c         C   sl   |  d  d j o d d f Sn y# t  i   i |   } | d } Wn t d |    n X| i | i f S(	   Ni   R  i  Rh   i   t	   link_addrs8   Error in attempting to get hw address for interface [%s]t         (   t   dnett   intfR   R   R   t   data(   Rs  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_if_raw_hwaddrF  s    c         C   s    t  i   } | i |   d i S(   NRe  (   R  R  R   R  (   t   ifnameR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_if_raw_addrO  s    c         C   s   t  i d t |  t   S(   Nt   16xh6s8x(   R   R   t   get_ift   SIOCGIFHWADDR(   Rs  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  S  s    c         C   s6   y t  |  t  d d !SWn t j
 o d Sn Xd  S(   Ni   i   t       (   R  t   SIOCGIFADDRRv   (   Rs  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  V  s    c           C   s"   t  d   t d   t i     S(   Nc         S   s   |  d  S(   i    (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   `  s    c         S   s   |  d  d j S(   i   N(   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   `  s    (   RN   R"   t   pcapt   findalldevs(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_if_list^  s    c           C   s,   y t  i   SWn t j
 o d Sn Xd  S(   NR  (   R  t	   lookupdevRs   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_working_ifa  s    c         C   s   t  d  d  S(   Ns1   attach_filter() should not be called in PCAP mode(   R   (   R   R"   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   attach_filterg  s    c         C   s   t  d  d  S(   Ns4   set_promisc() should not be called in DNET/PCAP mode(   R   (   R   Rs  RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   set_promisci  s    c          C   s^   t  d d  }  g  } |  i   |  i   x. |  D]& } | i | i d  d i    q0 W| S(   Ns   /proc/net/devRg   R   i    (   Rl   t   readlineRf   Rp   Rn   (   R   t   lstR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  m  s    

 $c          C   s^   xW t    D]L }  |  d j o q
 n t i d t |  t   d } | t @o |  Sq
 q
 Wd S(   NR  t   16xH14xi    (   R  R   R   R  t   SIOCGIFFLAGSt   IFF_UP(   R   t   ifflags(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  u  s    
 c   	      C   s:  t  p d  Sn y) t i d t i i t i | f  } Wn& t j
 o } t i	 d  d  Sn X| i
   } | i   o t d   n t | d  } d } x7 | d D]+ } | t i d t t | i     7} q Wt o# t i d | t |  d	  } n  t i d
 | t |  d  } |  i t t |  d  S(   Ns   %s -i %s -ddd -s 1600 '%s's   Failed to execute tcpdump: (%s)s   Filter parse errori    R   i   t   HBBIt   HLi$   t   HIi   (   t   TCPDUMPR   t   popenR   R   t   tcpdumpRd  R  R  R   t	   readlinesR~   R   Rr   R   R   RN   R   Rp   t   X86_64t   idt
   setsockoptt
   SOL_SOCKETt   SO_ATTACH_FILTER(	   R   R"   R   R   t   linesR    t   bpfR   t   bpfh(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  }  s&    )	 )#c         C   sO   t  i d t |  t d d  } | o
 t } n t } |  i t | |  d  S(   Nt   IHH8si    R   (   R   R   t   get_if_indext   PACKET_MR_PROMISCt   PACKET_ADD_MEMBERSHIPt   PACKET_DROP_MEMBERSHIPR  t
   SOL_PACKET(   R   Rs  RB   t   mreqt   cmd(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    !
c          C   s0   g  }  d   } t  i   } | i | |   GH|  S(   Nc         S   s   |  \ } } | i  |   d  S(   N(   Rf   (   R`  R  R  Rc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   addrt  s    (   R  Rf  t   loop(   t   rtlstR  Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   new_read_routes  s
    	c       
   C   s  t  o t i d  }  n* t o t i d  }  n t i d  }  d } t } g  } x=|  i   D]/} | p Pn | i   } | i d  d j o qb n | i d  d j o- d } | i d  d j o
 t } qb qb n | d j o qb n | p Pn t  o, | i	   d	  \ } } } } }	 }
 } } nS | o) | i	   d
  \ } } } } } } } n# | i	   d  \ } } } } } } | i d  d j o qb n | d j o d } d } n t  o t
 |  } nV d | j o+ | i	 d  \ } } t t |   } n t | i d  d d	  } | d d | i d  7} t
 |  } d | j o
 d } n t |  } | i | | | | | f  qb W|  i   | S(   Ns   netstat -rvns   netstat -rnWs   netstat -rni    s   ----t   Destinationi   t   Mtui   i   i   t   Lct   defaultl    R   R   s   .0i   t   Gs   0.0.0.0(   t   SOLARISR   R  t   FREEBSDRZ   R  Rn   Rm   R[   Rp   R   R   Rr   t   countRg  Rf   R~   (   R   t   okt   mtu_presentR_  R   R  t   maskRc  t   netift   mxfrgt   rttt   reft   flgt   uset   mtut   netmaskRl  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR^    s`     
,)"

 
c          C   s/   t  i   }  h  } d   } |  i | |  | S(   Nc         S   s   |  i  d  p d  Sn |  i  d  p d  Sn |  d i } t |  } |  d i } t |  } | | | | f | |  d <d  S(   NRe  R  R  (   R  R  R   R   (   Rs  R  t   rawipR   t   rawllt   ll(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   addif  s    (   R  R  R  (   R   t   ifflistR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   read_interfaces  s
    	
c          C   s  t  d d  }  g  } t i t i t i  } t | t t i d d   } t i d | d d ! d } | t i j o t | t	 t i d d   } t i
 t i d	 | d
 d ! d  } t i
 t i d	 | d
 d ! d  | @} t | d
 d ! } | i | | d d | f  n t d |  xz|  i   d D]h}	 |	 i   \ }
 } } } } } } } } } } t | d  } | t @d j o q8n | t @o q8n y" t | t t i d |
   } Wn t j
 o d } n] Xt i d | d d ! d } | t i j o t | d
 d ! } n t d |
 | f  q8| i t i t | d   d @t i t | d   d @t t i d	 t | d    |
 | f  q8W|  i   | S(   Ns   /proc/net/routeRg   t   16s16xR  t   hi   i   i    t   Ii   i   s   0.0.0.0s(   Interface lo: unkown address family (%i)i   s(   Interface %s: unkown address family (%i)l    (   Rl   R4   RZ  R[  R(   R  R   R   R   t   SIOCGIFNETMASKt   ntohlR   Rf   R   R  Rp   Rr   t   RTF_UPt
   RTF_REJECTRv   t   htonlR   R~   (   R   R_  R   t   ifreqt
   addrfamilyt   ifreq2Rb  R  Rl  R   Rs  Rc  t   flagsR6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR^    sF    &*  -"
c         C   s8   t  i    } t | | t i d |    } | i   | S(   NR  (   R4   R(   R   R   R~   (   Rs  R  R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    
c         C   s*   t  t i d t |  t  d d ! d  S(   NR  i   i   i    (   Rr   R   R   R  t   SIOCGIFINDEX(   Rs  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  *  s    c         C   s6   t  |  t d  } t i d |  \ } } | | d S(   Nt   12345678t   IIg    .A(   R(   t
   SIOCGSTAMPR   R   (   t   sockt   tsR   t   us(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_last_packet_timestamp-  s    c         C   s   t  t |    S(   N(   R   R  (   Rs  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRg  3  s    c         C   sM   t  |   \ } } | t t g j o t |  Sn t d | |  f   d  S(   Ns2   Unsupported address family (%i) for interface [%s](   R  t   ARPHDR_ETHERt   ARPHDR_LOOPBACKR   R   (   Rs  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_if_hwaddr6  s    ix   c         C   s   t  t t |    } | d d @d j o% d | d d @| d | d f Sn t i i |   \ } } } | d	 j o d
 Sn | d j o
 | }  n t i t i |    } | d  j o d  Sn | i
   Sd  S(   Ni    i   i   s   01:00:5e:%.2x:%.2x:%.2xi   i   i   i   R  s   ff:ff:ff:ff:ff:ffs   0.0.0.0(   RN   R   R5   R   Rf  t   dnet_arp_objectR   R  Re  R   t   ntoa(   R   t   chainCCt   tmpRs  R  Rc  t   res(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   getmacbyipJ  s    %
c   	      C   s  t  t t |    } | d d @d j o% d | d d @| d | d f Sn t i i |   \ } } } | d	 j p |  t i i |  j o d
 Sn | d j o
 | }  n t i |   o; t |  \ } } | p t i   | t	 j  o | Sq n t
 t d t  t d d d |   d t d | d d d d d | d d } | d  j	 o* | i i } | t i   f t |  <| Sn d  S(   Ni    i   i   s   01:00:5e:%.2x:%.2x:%.2xi   i   i   i   R  s   ff:ff:ff:ff:ff:ffs   0.0.0.0R  t   ops   who-hast   pdstR   Rd  t   timeoutR  R  t   nofilter(   RN   R   R5   R   Rf  R  Rr  R  R   t
   ARPTIMEOUTt   srp1t   Ethert   ETHER_BROADCASTt   ARPt	   ETH_P_ARPR   t   payloadt   hwsrc(	   R   R  R  Rs  R  Rc  R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  Y  s0    %&
%	c         c   s  t  i |  } d } | |  d } d } x  d | >| j  o | d 7} q, Wt d | d d  }	 d |	 d }
 t | d  } d } x | d j p | o7 g  } t |  D] } | | i d |
  q ~ } n | d 7} d } x | d | j  o} | } | d 7} xL t |  D]> } | |
 @} | |	 L} | | | | N} | | | |	 >O} qW| | j  o |  | Vq q W| p Pq q d S(   s*  iterate through a sequence in random order.
       When all the values have been drawn, if forever=1, the drawing is done again.
       If renewkeys=0, the draw will be in the same order, guaranteeing that the same
       number will be drawn in not less than the number of integers of the sequencei   i   i    i   i   N(   t   randomt   RandomR   t   maxt   xranget   randintR   (   t   inft   supt   seedt   forevert	   renewkeyst   rndt	   sbox_sizet   topR   t   fst   fsmaskt   roundst   turnst   _[1]RR   t   sboxR   t   ctt   lsb(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   randseqz  s8    7

 

t   VolatileValuec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   d |  i  i S(   Ns   <%s>(   R   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    c         C   s0   | d j o t  |   n t |  i   |  S(   Nt   __setstate__(   t   AttributeErrorRD   t   _fix(   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   d  S(   N(   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   RV   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   		t	   RandFieldc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   RandNumc           B   s&   e  Z d  Z d  Z d   Z d   Z RS(   i    c         C   s   t  | |  |  _ d  S(   N(   R  t   seq(   R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   |  i  i   S(   N(   R  t   next(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	t   RandNumGammac           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   alphat   beta(   R   R"  R#  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   s"   t  t t i |  i |  i    S(   N(   Rr   t   roundR  t   gammavariateR"  R#  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s   	t   RandNumGaussc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   mut   sigma(   R   R'  R(  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   s"   t  t t i |  i |  i    S(   N(   Rr   R$  R  t   gaussR'  R(  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR&    s   	t   RandNumExpoc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   lambd(   R   R+  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  t t i |  i    S(   N(   Rr   R$  R  t   expovariateR+  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR*    s   	t   RandBytec           B   s   e  Z d    Z RS(   c         C   s   t  i |  d d  d  S(   Ni    l    i   i   l    l    (   R  R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR-    s   t	   RandShortc           B   s   e  Z d    Z RS(   c         C   s   t  i |  d d  d  S(   Ni    l    i   i   l      l    (   R  R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR.    s   t   RandIntc           B   s   e  Z d    Z RS(   c         C   s   t  i |  d d  d  S(   Ni    l    i    i   l        l    (   R  R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR/    s   t   RandSIntc           B   s   e  Z d    Z RS(   c         C   s   t  i |  d d  d  S(   Nl    i   i   l        l     l        l    (   R  R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR0    s   t   RandLongc           B   s   e  Z d    Z RS(   c         C   s   t  i |  d d  d  S(   Ni    l    i@   i   l            l    (   R  R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR1    s   t	   RandSLongc           B   s   e  Z d    Z RS(   c         C   s   t  i |  d d  d  S(   Nl    i?   i   l            l         l            l    (   R  R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR2    s   t
   RandChoicec           B   s   e  Z d    Z d   Z RS(   c         G   s$   | p t  d   n | |  _ d  S(   Ns$   RandChoice needs at least one choice(   t	   TypeErrort   _choice(   R   R\   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  i |  i  S(   N(   R  t   choiceR5  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR3    s   	t
   RandStringc           B   s   e  Z d  d  Z d   Z RS(   t>   ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789c         C   s   | |  _  | |  _ d  S(   N(   t   charst   size(   R   R:  R9  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   s:   d } x- t  |  i  D] } | t i |  i  7} q W| S(   NR   (   R   R:  R  R6  R9  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
     (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR7    s   t   RandBinc           B   s   e  Z d    Z RS(   c         C   s/   t  i |  | d i t t t d     d  S(   NR   i   (   R7  R   RU   RN   R   R   (   R   R:  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR;    s   t   RandTermStringc           B   s   e  Z d    Z d   Z RS(   c      	   C   s;   t  i |  | d i t t t d d     | |  _ d  S(   NR   i   i   (   R7  R   RU   RN   R   R   t   term(   R   R:  R=  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    .c         C   s   t  i |   |  i S(   N(   R7  R  R=  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR<    s   	t   RandIPc           B   s   e  Z d  d  Z d   Z RS(   s	   0.0.0.0/0c         C   s   t  |  |  _ d  S(   N(   t   NetR   (   R   t
   iptemplate(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   |  i  i   S(   N(   R   R6  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR>    s   t   RandMACc           B   s   e  Z d  d  Z d   Z RS(   R|  c         C   s   | d 7} | i  d  } d |  _ x t d  D] } | | d j o t   } nc d | | j o> | | i  d  \ } } t t | d  t | d   } n t | | d  } |  i | f 7_ q/ Wd  S(   Ns
   :*:*:*:*:*R   i   R|  R~  i   (    (   Rp   R   R   R-  R  Rr   (   R   t   templateR   R
  R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    
	 %c         C   s   d |  i  S(   Ns   %02x:%02x:%02x:%02x:%02x:%02x(   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRA  
  s   t   RandOIDc           B   s8   e  Z d e d   e d  d  Z d   Z d   Z RS(   g?g{Gz?c         C   s   | |  _  | d  j	 ok | i d  } xY t t |   D]A } d | | j o* t t t | | i d    | | <q8 q8 Wn | |  _ | |  _	 | |  _
 d  S(   NR   R~  (   t   ori_fmtR   Rp   R   Rq   Ro   RN   Rr   t   fmtt   deptht   idnum(   R   RE  RF  RG  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	 2		c         C   s=   |  i  d  j o d |  i i Sn d |  i i |  i  f Sd  S(   Ns   <%s>s	   <%s [%s]>(   RD  R   R   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   '  s    c         C   s6  |  i  d  j oE d i t t g  } t d |  i  D] } | |  i q4 ~   Sn g  } x |  i  D] } | d j o | i t |  i   qe | d j oB | t t g  } t d |  i  D] } | |  i q ~  7} qe t	 |  t
 j o  | i t t i |     qe | i |  qe Wd i |  Sd  S(   NR   i   R|  s   **(   RE  R   RU   RN   R   R  RF  RG  Rf   R   Ro   R  t	   randrange(   R   R  R   t   oidt   _[2](    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ,  s    E
 B N(   R   R   R   R*  R   RV   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRC    s   
	t   RandASN1Objectc           B   s    e  Z d d   Z d d  Z RS(   c         C   sN   | d  j o+ t d   t d   t i i     } n | |  _ d |  _ d  S(   Nc         S   s   |  i  S(    (   t	   _asn1_obj(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   A  s    c         S   s   t  |  d   S(   RL  (   t   hasattr(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   B  s    R8  (   R   RN   R"   t   ASN1_Class_UNIVERSALR  t   valuest   objlistR9  (   R   RP  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   ?  s
    	"	i    c            s7  t  i |  i  } t | t  o  | t t  i d d    Sn t | t  o] t t  i d  d  } | d i	 g  } t
 |  D] } | t  i |  i  q ~   Snm t | t  o\   d j  oO t t  i d  d  } | t   f d   |  i d	 |  i  g |   Sn t t t  i d d    S(
   Ni    i  g?i   R   i
   g{Gz?c            s   |  i    d   S(   i   (   R  (   R6   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   N  s    RP  (   R  R6  RP  t
   issubclasst   ASN1_INTEGERRr   R)  t   ASN1_STRINGR,  RU   R   R9  t   ASN1_SEQUENCERN   R   (   R   R   Rb   R   R  R   (    (   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  E  s     D6N(   R   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK  >  s   t   RandDHCPOptionsc           B   s    e  Z d d d   Z d   Z RS(   c         C   s   | d  j o t d  } n | |  _ | d  j o t t d d   } n | |  _ t i   |  _ |  i i	 d  |  i i	 d  d  S(   Ng?i    i   t   padt   end(
   R   R*  R:  R;  R  t   rndstrt   DHCPOptionsRO  t   _optst   remove(   R   R:  RX  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   R  s    		c         C   s   g  } x| t  |  i  D]k } t i |  i  } t |  t j o | i | |  i d f  q | i | i	 | i
   i   f  q W| S(   Ni   (   R   R:  R  R6  RZ  R   R   Rf   RX  R  t   randvalR  (   R   R  RR   Rb   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  \  s     &N(   R   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRU  Q  s   
t   AutoTimec           B   s   e  Z d d   Z d   Z RS(   c         C   s1   | d  j o d |  _ n t i   | |  _ d  S(   Ni    (   R   t   diffR   (   R   t   base(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   j  s    c         C   s   t  i    |  i S(   N(   R   R^  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  o  s    N(   R   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR]  i  s   t   IntAutoTimec           B   s   e  Z d    Z RS(   c         C   s   t  t i   |  i  S(   N(   Rr   R   R^  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  s  s    (   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR`  r  s   t   ZuluTimec           B   s   e  Z d d   Z d   Z RS(   c         C   s   | |  _  d  S(   N(   R^  (   R   R^  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   x  s    c         C   s&   t  i d t  i t  i    |  i   S(   Ns   %y%m%d%H%M%SZ(   R   t   strftimet   gmtimeR^  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  z  s    N(   R   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRa  w  s   t   DelayedEvalc           B   s    e  Z d  Z d   Z d   Z RS(   s.    Exemple of usage: DelayedEval("time.time()") c         C   s   | |  _  d  S(   N(   t   expr(   R   Re  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  |  i  S(   N(   t   evalRe  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   RW  R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRd  ~  s   	t   IncrementalValuec           B   s#   e  Z d  d d d  Z d   Z RS(   i    i   ic         C   s&   | |  _  |  _ | |  _ | |  _ d  S(   N(   R   RB   t   stept   restart(   R   R   Rh  Ri  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   sB   |  i  } |  i  |  i j o |  i |  _  n |  i  |  i 7_  | S(   N(   RB   Ri  R   Rh  (   R   R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    	(   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRg    s   g{Gz?c         C   s   t  i  d t |    }  t |   } | d  j o t d t | |   } n x6 t i t |  |  D] } t i	 d d  |  | <qg W|  i
   S(   Nt   Bi   i    i   (   R   R   Rq   R   R  Rr   R  t   sampleR  R  t   tostring(   R   Rc   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   corrupt_bytes  s     c         C   s   t  i  d t |    }  t |   d } | d  j o t d t | |   } n x< t i t |  |  D]" } |  | d c d | d >N<qk W|  i	   S(   NRj  i   i   (
   R   R   Rq   R   R  Rr   R  Rk  R  Rl  (   R   Rc   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   corrupt_bits  s      t   CorruptedBytesc           B   s    e  Z d  d d  Z d   Z RS(   g{Gz?c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   Rc   R   (   R   R   Rc   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    		c         C   s   t  |  i |  i |  i  S(   N(   Rm  R   Rc   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    N(   R   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRo    s   t   CorruptedBitsc           B   s   e  Z d    Z RS(   c         C   s   t  |  i |  i |  i  S(   N(   Rn  R   Rc   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRp    s   t
   ASN1_Errorc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRq    s   t   ASN1_Encoding_Errorc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRr    s   t   ASN1_Decoding_Errorc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRs    s   t   ASN1_BadTag_Decoding_Errorc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRt    s   t	   ASN1Codecc           B   s2   e  Z d    Z d d  Z d d  Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   _stem(   R  t   stem(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   register_stem  s    c         C   s   |  i  i | d | S(   Nt   context(   Rv  t   dec(   R  R   Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRz    s    c         C   s   |  i  i | d | S(   NRy  (   Rv  t   safedec(   R  R   Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR{    s    c         C   s   |  i  S(   N(   Rw  (   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_stem  s    N(   R   R   Rx  R   Rz  R{  R|  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRu    s   	t   ASN1_Codecs_metaclassc           B   s   e  Z e Z RS(    (   R   R   Ru  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR}    s   t   ASN1_Codecsc           B   sD   e  Z e Z d  Z d Z d Z d Z d Z d Z	 d Z
 d Z d Z RS(	   i   i   i   i   i   i   i   i   i	   (   R   R   R}  t   __metaclass__t   BERt   DERt   PERt   CERt   LWERt   BACnett   OERt   SERt   XER(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~    s   t   ASN1Tagc           B   sD   e  Z d d d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s@   t  i |  | |  | |  _ | d  j o
 h  } n | |  _ d  S(   N(   R   R   t   _contextR   t   _codec(   R   R   R   Ry  t   codec(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
    	
c         C   s"   |  i  |  i |  i |  i |  i  S(   N(   R   R   R   R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   clone  s    c         C   s   | |  _  d  S(   N(   RL  (   R   t   asn1obj(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   register_asn1_object  s    c         C   s5   t  |  d  o |  i |  Sn t d |    d  S(   NRL  s)   %r does not have any assigned ASN1 object(   RM  RL  Rq  (   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   asn1_object  s    c         C   s   | |  i  | <d  S(   N(   R  (   R   t   codecnumR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   register  s    c         C   sC   y |  i  | } Wn+ t j
 o } t d | |  f   n X| S(   Ns   Codec %r not found for tag %r(   R  t   KeyErrorRq  (   R   R  R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   get_codec  s
    N(	   R   R   R   R   R  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   				t   ASN1_Class_metaclassc           B   s   e  Z e Z d    Z RS(   c      	   C   s:  x_ | D]W } xN | i  i   D]= \ } } | | j o$ t | t  o | i   | | <q q Wq Wh  } xr | i   D]d \ } } t |  t j o' t | |  } | | | <| | | <qu t | t  o | | | <qu qu W| | d <t i |  | | |  }  x4 |  i  i   D]# } t | t  o |  | _	 qqW|  S(   NR  (
   R?   R  R`   R  R  R   Rr   R  RO  Ry  (   R  R  R  Ry   t   bRR   R
  R	  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s,       

 (   R   R   R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t
   ASN1_Classc           B   s   e  Z e Z RS(    (   R   R   R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   RN  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 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(#   t	   UNIVERSALiiii    i   i   i   i   i   i   i   i   i	   i
   i   i   i   i0   i1   i   i   i   i   i   i   i   i   i   i   i   i   i   iA   iC   (%   R   R   R  t   ERRORt   RAWt   NONEt   ANYt   BOOLEANt   INTEGERt
   BIT_STRINGt   STRINGt   NULLt   OIDt   OBJECT_DESCRIPTORt   EXTERNALt   REALt
   ENUMERATEDt   EMBEDDED_PDFt   UTF8_STRINGt   RELATIVE_OIDt   SEQUENCEt   SETt   NUMERIC_STRINGt   PRINTABLE_STRINGt
   T61_STRINGt   VIDEOTEX_STRINGt
   IA5_STRINGt   UTC_TIMEt   GENERALIZED_TIMEt   GRAPHIC_STRINGt   ISO646_STRINGt   GENERAL_STRINGt   UNIVERSAL_STRINGt   CHAR_STRINGt
   BMP_STRINGt	   COUNTER32t
   TIME_TICKS(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRN    sF   t   ASN1_Object_metaclassc           B   s   e  Z d    Z RS(   c         C   s]   t  t |   i |  | | |  } y | i i |  Wn! t d | i | i f  n X| S(   Ns   Error registering %r for %r(   R  R  R  t   tagR  R   R  (   R  R  R  Ry   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  8  s    !(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  7  s   t   ASN1_Objectc           B   se   e  Z e Z e i Z d    Z d   Z d   Z	 d   Z
 d d  Z d d  Z d   Z d   Z RS(	   c         C   s   | |  _  d  S(   N(   RB   (   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   D  s    c         C   s   |  i  i |  i |  i  S(   N(   R  R  t   encRB   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  F  s    c         C   s&   d |  i  i d |  i i  |  i f S(   Ns   <%s[%r]>R  (   R?   R   R   R   RB   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   H  s    c         C   s   |  i  t i  S(   N(   R  R   t   ASN1_default_codec(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   J  s    i    c         C   s   d | t  |   d S(   Ns     s   
(   t   repr(   R   t   lvl(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   strshowL  s    c         C   s   |  i  |  GHd  S(   N(   R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   showN  s    c         C   s   |  i  | j S(   N(   RB   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   P  s    c         C   s   t  |  i |  S(   N(   t   cmpRB   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __cmp__R  s    (   R   R   R  R  RN  R  R  R   R  RV   R   R  R  R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  A  s   						t   ASN1_DECODING_ERRORc           B   s/   e  Z e i Z d d   Z d   Z d   Z RS(   c         C   s   t  i |  |  | |  _ d  S(   N(   R  R   t   exc(   R   RB   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   W  s    c         C   s3   d |  i  i d |  i i  |  i |  i i d f S(   Ns   <%s[%r]{{%s}}>R  i    (   R?   R   R   R   RB   R  R\   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   Z  s    c         C   s.   t  |  i t  o |  i i |  Sn |  i S(   N(   R`   RB   R  R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ]  s    N(	   R   R   RN  R  R  R   R   RV   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  U  s   		t
   ASN1_forcec           B   s   e  Z e i Z d    Z RS(   c         C   s.   t  |  i t  o |  i i |  Sn |  i S(   N(   R`   RB   R  R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  d  s    (   R   R   RN  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  b  s   	t   ASN1_BADTAGc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  i  s   RR  c           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRR  l  s   RS  c           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRS  o  s   t   ASN1_BIT_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  r  s   t   ASN1_PRINTABLE_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  u  s   t   ASN1_T61_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  x  s   t   ASN1_IA5_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  {  s   t   ASN1_NUMERIC_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ~  s   t   ASN1_VIDEOTEX_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ASN1_UTC_TIMEc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ASN1_TIME_TICKSc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ASN1_BOOLEANc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t	   ASN1_NULLc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ASN1_COUNTER32c           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   RT  c           B   s   e  Z e i Z d  d  Z RS(   i    c         C   sN   d | d |  i  i d } x+ |  i D]  } | | i d | d  7} q& W| S(   Ns     s   # %s:s   
R  i   (   R   R   RB   R  (   R   R  R   Rb   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    
 (   R   R   RN  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRT    s   	t   ASN1_SETc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ASN1_OIDc           B   s#   e  Z e i Z d    Z d   Z RS(   c         C   s&   t  i i |  } t i |  |  d  S(   N(   R   t   mibt   _oidR  R   (   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s2   d |  i  i d |  i i  t i i |  i  f S(   Ns   <%s[%r]>R  (   R?   R   R   R   R   R  t   _oidnameRB   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    (   R   R   RN  R  R  R   RV   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   		t   BER_Exceptionc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BER_Decoding_Errorc           B   s    e  Z d d d   Z d   Z RS(   c         C   s&   t  i |  |  | |  _ | |  _ d  S(   N(   Rs   R   t	   remainingt   decoded(   R   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   sc   t  i |   } t |  i t  o | d |  i i   7} n | d |  i 7} | d |  i 7} | S(   Ns   
### Already decoded ###
%ss   
### Already decoded ###
%rs   
### Remaining ###
%r(   Rs   R   R`   R  t   BERcodec_ObjectR  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    N(   R   R   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BER_BadTag_Decoding_Errorc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   c         C   s   |  d j o | d j o t  |   Sn d } xA |  p | d j o, t  |  d @ | } |  d L}  | d 8} q1 Wt |  d j o  t d t |  | f   n t  t |  d B | S(	   Ni   i    R   i   l    i   s4   BER_len_enc: Length too long (%i) to be encoded [%r]i   (   R   Rq   R  (   R   R:  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   BER_len_enc  s    
 c         C   s   t  |  d  } | d @p | |  d f Sn | d M} t |   | j o* t d t |   d | f d |   n d } x3 |  d | d !D]  } | d K} | t  |  O} q W| |  | d f S(	   Ni    i   i   i   s,   BER_len_dec: Got %i bytes while expecting %iR  l    l    (   R   Rq   R  (   R   R   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   BER_len_dec  s    
* 
c         C   s   g  } xh |  p | d j oS | i  d |  d @ t |  d j o | d c d O<n |  d L}  | d 8} q	 Wd i g  } | D] } | t |  q ~  S(   Ni    i   i   i   i   R   (   R:  Rq   RU   R   (   R   R:  R6   R  RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   BER_num_enc  s    
c         C   s   d } xR t  t |    D]> } t |  |  } | d K} | | d @O} | d @p Pq q W| d @o t d d |   n | |  | d f S(   Ni    i   i   i   s*   BER_num_dec: unfinished number descriptionR  i   (   R   Rq   R   R  (   R   R6   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   BER_num_dec  s     
	t   BERcodec_metaclassc           B   s   e  Z d    Z RS(   c         C   sc   t  t |   i |  | | |  } y | i i | i |  Wn! t d | i | i f  n X| S(   Ns   Error registering %r for %r(   R  R  R  R  R  R  R   (   R  R  R  Ry   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    !(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   R  c           B   s   e  Z e Z e i Z e i Z	 e
 d     Z e
 d    Z e
 d    Z e
 d    Z e
 d    Z e
 d	 e d   Z e
 d	 e d   Z e
 d	 d   Z e
 d    Z RS(
   c         C   s   |  i  i |  S(   N(   R  R  (   R  RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s1   | p& t  d |  i |  i f d |  n d  S(   Ns+   %s: Got empty object while expecting tag %rR  (   R  R   R  (   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   check_string  s    c         C   so   |  i  |  |  i t | d  j o@ t d |  i t | d  t | d  |  i f d |  n | d S(   Ni    s'   %s: Got tag [%i/%#x] while expecting %rR  i   (   R  R  R   R  R   (   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   check_type  s
    :c         C   s=   |  i  |  } | p t d |  i d |  n t |  S(   Ns%   %s: No bytes while expecting a lengthR  (   R  R  R   R  (   R  R   t   s2(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   check_type_get_len  s
    c         C   si   |  i  |  \ } } t |  | j  o, t d |  i t |  | f d |  n | | |  | | f S(   Ns#   %s: Got %i bytes while expecting %iR  (   R  Rq   R  R   (   R  R   R   t   s3(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   check_type_check_len  s
    &c         C   s   | d  j o |  i i } n |  i |  t | d  } | | j oK | } t |  d j o | d  d } n t d | | f d |  n | | i t i	  } | i
 | | |  S(   Ni    i   i   s   ...s   Unknown prefix [%02x] for [%r]R  (   R   R  Ry  R  R   Rq   R  R  R~  R  Rz  (   R  R   Ry  t   safeRc   RT  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   do_dec"  s     c         C   s   | p |  i  | | |  Sn y |  i  | | |  SWn t j
 o7 } t i | i | |  \ } } t |  | f SnV t j
 o } t | d | d f Sn, t j
 o } t | d | d f Sn Xd  S(   NR  R   (	   R  R  R  Rz  R  R  R  R  Rq  (   R  R   Ry  R  R|   Rb   t   remain(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRz  0  s    c         C   s   |  i  | | d t S(   NR  (   Rz  R[   (   R  R   Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR{  >  s    c         C   s;   t  |  t j o t i |  Sn t i t |   Sd  S(   N(   R   R   t   BERcodec_STRINGR  t   BERcodec_INTEGERRr   (   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  C  s    N(   R   R   R  R  R~  R  R  RN  R  R  t   classmethodR  R  R  R  R  R   RZ   R  Rz  R{  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   		R  c           B   s5   e  Z e i Z e d     Z e d e d   Z	 RS(   c         C   s   g  } x| | i  | d @ d | j o
 d j  n o Pn d | j o
 d j n o | i  d  n | d L} | p Pq	 q	 t t |  } | i  t t |    | i  t |  i   | i   d i |  S(   Ni   ii    i   i   R   (   Rf   RN   R   R  Rq   R  t   reverseRU   (   R  R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  Q  s    

c         C   s   |  i  |  \ } } } d } | oN t | d  d @o
 d } n x, | D]  } | d K} | t |  O} qK Wn |  i |  | f S(   Nl    i    i   l i   (   R  R   R  (   R  R   Ry  R  R   RT  R6   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  b  s    
 
N(
   R   R   RN  R  R  R  R  R   RZ   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  O  s   	t   BERcodec_BOOLEANc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  o  s   t   BERcodec_NULLc           B   s    e  Z e i Z e d     Z RS(   c         C   s<   | d j o t  |  i  d Sn t |  |   i |  Sd  S(   Ni    Rh   (   R   R  R  R  (   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  t  s    (   R   R   RN  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  r  s   	R  c           B   s5   e  Z e i Z e d     Z e d e d   Z	 RS(   c         C   s!   t  |  i  t t |   | S(   N(   R   R  R  Rq   (   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  }  s    c         C   s.   |  i  |  \ } } } |  i i |  | f S(   N(   R  R  R  (   R  R   Ry  R  R   RT  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    N(
   R   R   RN  R  R  R  R  R   RZ   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  {  s   	t   BERcodec_BIT_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_PRINTABLE_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_T61_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_IA5_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_UTC_TIMEc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_TIME_TICKSc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_COUNTER32c           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_SEQUENCEc           B   s5   e  Z e i Z e d     Z e d e d   Z	 RS(   c            sY   t  |  t j	 o% d i t   f d   |   } n t   i  t t |   | S(   NR   c            s   |  i    i  S(    (   R  R  (   R6   (   R  (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   R   R   RU   RN   R   R  R  Rq   (   R  R   (    (   R  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    %c   
   	   C   s  | d  j o |  i i } n |  i |  \ } } | |  | | } } g  } x | o y t i | | |  \ } } WnT t j
 oH }	 |	 i | 7_ |	 i d  j	 o | i	 |	 i  n | |	 _   n X| i	 |  qP Wt
 |  | j  o t d d |  n |  i |  | f S(   Ns#   Not enough bytes to decode sequenceR  (   R   R  Ry  R  R  Rz  R  R  R  Rf   Rq   R  (
   R  R   Ry  R  R   t   stRT  R*  Rb   t   err(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s$    
	N(
   R   R   RN  R  R  R  R  R   RZ   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	t   BERcodec_SETc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BERcodec_OIDc           B   s5   e  Z e i Z e d     Z e d e d   Z	 RS(   c         C   s   g  } | i  d  i d  D] } | t |  q ~ } t |  d j o# | d c d | d 7<| d =n d i g  } | D] } | t |  q ~  } t |  i  t t |   | S(   NR   i   i   i(   i    R   (	   Rn   Rp   Rr   Rq   RU   R  R   R  R  (   R  RI  R  R6   R  RJ  RR   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    90c   	      C   s   |  i  |  \ } } } g  } x+ | o# t |  \ } } | i |  q! Wt |  d j o, | i d | d d  | d c d ;<n |  i d i g  } | D] } | t |  q ~   | f S(   Ni    i(   i   R   (   R  R  Rf   Rq   R:  R  RU   R   (	   R  R   Ry  R  R   RT  R  R  RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
N(
   R   R   RN  R  R  R  R  R   RZ   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	s   ^[0-9]+$s'   ^([a-zA-Z_][a-zA-Z0-9_-]*)\(([0-9]+)\)$s4   $\s*([a-zA-Z0-9_-]+)\s+OBJECT[^:]+::=\s*\{([^\}]+)\}s   "[^"]*"s	   --.*(|
)t   MIBDictc           B   s/   e  Z d    Z d   Z d   Z g  d  Z RS(   c         C   s   | i  d  o | d } n | i d  p | d 7} n d } d } xa |  i   D]S } | i  |  | d  o5 | t |  |  j  o t |  |  } | } q qU qU W| | | d !f S(   NR   i   i    i(   R   R   RQ   Rq   (   R   R6   R  t   rootRR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   _findroot  s     c         C   s   |  i  |  \ } } | | S(   N(   R  (   R   R6   R  t	   remainder(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   | i  d  i d  } t |  d } x0 | d j o" t i | |  o | d 8} q+ W| d j p | | |  j o | Sn |  | | | | <d i | |  S(   NR   i   i    (   Rn   Rp   Rq   t   _mib_re_integerRL  RU   (   R   R6   t   xlRc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    $c         K   sa  g  } |  i    D] } | | |  | f q ~ } g  } |  i    D] } | |  | qB ~ } x8 | D]0 } | | j o | i |  i |  |  qc qc Wd } x( | D]  \ } }	 | d |	 | f 7} q W| d 7} xq | D]i \ } }	 |  i |	 d   \ }
 } | d |	 d } |
 d j o |  |
 }
 n | d |
 |	 | f 7} q W| d 7} t | |  d  S(	   Ns   digraph "mib" {
	rankdir=LR;

s   	"%s" [ label="%s"  ];
s   
ii   R   s   	"%s" -> "%s" [label="%s"];
s   }
(   RQ   Rf   t   oidnameR  R   (   R   t
   other_keysRA   R  RR   t   nodesRJ  t   oidsR   Rb   t   parentR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _make_graph  s(    1+ ! 
 
(   R   R   R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   				c   
      C   s  |  | j p |  | j o |  | j Sn g  } d } x | D] } t  i |  o | i |  q; t |  } | | j o
 d } n | | j o | | } n | | j o | | } n t |  t j o | | 7} q; | i |  q; W| o | | |  <t Sn | | |  <| i   } d } x^ | t |  j  oJ | | }	 t	 |	 | |	 | h   o | |	 =| | =d } q%| d 7} q%Wt
 Sd  S(   Ni    i   (   R  RL  Rf   R;   R   R   RZ   RQ   Rq   t   mib_registerR[   (
   t   identR   t   the_mibt
   unresolvedt   resvalt   not_resolvedR
  RQ   R   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  
	  s@     




c         C   s  h  d g d <} h  } x: t  i i   D]) } t | t  i | i d  | |  q( Wt |   t j o |  g }  n x|  D]} x t |  D] } t |  } | i	   } d i
 t i d i
 t i |     } x t i |  D] }	 |	 i   \ }
 } t |
  }
 | i   } xL t t |   D]8 } t i | |  }	 |	 o |	 i   d | | <q*q*Wt |
 | | |  q Wq Wq| Wt d d  } x- | i   D] \ } } d i
 |  | | <qWx- | i   D] \ } } d i
 |  | | <qW| t  _ d  S(   Nt   1t   isoR   RT   i   R>   t   MIB(   R   R  RQ   R  Rp   R   R   R'   Rl   R-  RU   t   _mib_re_stringst   _mib_re_commentst   _mib_re_oiddeclt   finditert   groupsR;   R   Rq   t   _mib_re_bothRL  R   R  (   t	   filenamesR  R  RR   t   fnamesR  R   t   textt	   cleantextR  R  RI  R   t   newmibRb   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   load_mib1	  sB     '  *    t   Genc           B   s   e  Z d    Z RS(   c         C   s
   t  g   S(   N(   RM   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRP   W	  s    (   R   R   RP   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  V	  s   t   SetGenc           B   s/   e  Z d  d  Z d   Z d   Z d   Z RS(   i   c         C   s\   | |  _  t |  t j o | |  _ n0 t | t  o t |  |  _ n | g |  _ d  S(   N(   t   _iterpacketR   R   t   setR`   t
   PacketList(   R   R$  R#  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   [	  s    	c         C   s   | S(   N(    (   R   t   element(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   transfc	  s    c         c   s  x |  i  D] } t |  t j o t |  d j o} t | d  t j of t | d  t j oO | d | d j o6 | d } x) | | d j o | V| d 7} q Wq q
 t | t  o5 |  i p t | t  o x | D] } | Vq Wq
 | Vq
 Wd  S(   Ni   i    i   (	   R$  R   Ro   Rq   Rr   R`   R!  R#  t   Packet(   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRP   e	  s    
 T
+ c         C   s   d |  i  i   S(   Ns   <SetGen %s>(   R$  RV   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   r	  s    (   R   R   R   R'  RP   RV   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"  Z	  s   		R?  c           B   sG   e  Z d  Z d Z e i d  Z d   Z d   Z d   Z	 d   Z
 RS(   s7   Generate a list of IPs from a network address or a nameR   s   ^(\*|[0-2]?[0-9]?[0-9](-[0-2]?[0-9]?[0-9])?)\.(\*|[0-2]?[0-9]?[0-9](-[0-2]?[0-9]?[0-9])?)\.(\*|[0-2]?[0-9]?[0-9](-[0-2]?[0-9]?[0-9])?)\.(\*|[0-2]?[0-9]?[0-9](-[0-2]?[0-9]?[0-9])?)(/[0-3]?[0-9])?$c      
      s   | |  _  | i d  d g } |  i i |  p t i | d  | d <n t | d  } d     t   f d   | d i d  t | d  d   |  _ d  S(   NR   Rq  i    i   c         S   s   t  d t | d   } |  d j o
 d }  n |  i d  d j of t t |  i d   \ } } | | j o
 | } n | d | >@t | | d d | ?B d f }  n1 t |   d | >@t |   d d | ?Bd f }  |  S(	   Ni   i    R|  i   R~  l    i   (   i    i   (   R   R  Rm   RN   Rr   Rp   (   R  R  R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   parse_digit	  s    

10c            s     |  |  S(    (    (   R6   RJ   (   R)  (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   	  s    R   c         S   s   |  | S(    (    (   R6   t   nm(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   	  s    i   i   i   i    (   i   i   i   i    (	   R  Rp   t	   ipaddressRL  R4   R   Rr   RN   t   parsed(   R   Ra  R  R  (    (   R)  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   y	  s    		c      	   c   s   x t  |  i d   D]u } xl t  |  i d   D]W } xN t  |  i d   D]9 } x0 t  |  i d   D] } d | | | | f Vqb WqH Wq. Wq Wd  S(   Ni   i   i   i    s   %i.%i.%i.%i(   R  R,  (   R   R   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRP   	  s        c         C   sR   g  } x< |  i  D]1 } | i t t i | d | d d    q Wd i |  S(   Ni    i   R   (   R,  Rf   R   R  R  RU   (   R   R   R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR6  	  s
    
 /c         C   s   d |  i  S(   Ns   Net(%r)(   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   	  s    (   R   R   RW  R  Rj   Rk   R+  R   RP   R6  RV   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR?  u	  s   			R  c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   R  c         C   s   | |  _  g  |  _ g  } xj | i d  D]Y } d | j o9 | i d  |  i i t t t | i d     q( | i |  q( Wd i |  |  _ d  S(   NR   R~  s   %i(	   RI  t   cmptRp   Rf   Ro   RN   Rr   RU   RE  (   R   RI  RE  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   	  s    		 ,c         C   s   d |  i  S(   Ns   OID(%r)(   RI  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   	  s    c         c   s   g  } |  i  D] } | | d q ~ } x |  i t |  Vd } xp | t |  j o
 t  n | | |  i  | d j  o | | c d 7<Pn |  i  | d | | <| d 7} qF q+ d  S(   Ni    i   (   R-  RE  Ro   Rq   t   StopIteration(   R   R  RR   t   iiR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRP   	  s    (
(   R   R   R  R   RV   RP   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  	  s   		R%  c           B   sp  e  Z g  Z d# d  d# d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d# d# d
  Z d# d# d  Z d   Z d   Z d   Z d   Z d   Z d   Z d# d  Z d d# d  Z d# d  Z d   Z d# d  Z d# d  Z d# d  Z d# d  Z d# d  Z d# d# d# d  Z d   Z d   Z  d# d  Z! d# d   Z" d! d"  Z# RS($   R%  c         C   ss   | d j o t t t g } n | |  _ | d j o
 g  } n t | t  o | i } n | |  _ | |  _ d S(   s   create a packet list from a list of packets
           res: the list of packets
           stats: a list of classes that will appear in the stats (defaults to [TCP,UDP,ICMP])N(	   R   t   TCPt   UDPt   ICMPt   statsR`   R%  R  t   listname(   R   R  R  R3  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   	  s    	
	c         C   s   | S(   N(    (   R   t   elt(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _elt2pkt	  s    c         C   s
   | i    S(   N(   t   summary(   R   R5  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _elt2sum	  s    c         C   s   |  i  |  S(   N(   R8  (   R   R5  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   _elt2show	  s    c         C   sa  t  t d   |  i   } d } xq |  i D]f } d } xB | D]: } |  i |  i |  o | | c d 7<d } Pq> q> W| p | d 7} q+ q+ Wd } t i } xJ |  i D]? } | d | i | i	  | i
 d  | i | |  f 7} q W| d | i d  | i
 d  | i |  f 7} d | i
 d	  | i |  i  | i
 d  | | i
 d
  f S(   Nc         S   s
   |  d  f S(   i    (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   	  s    i    i   R   s    %s%s%sR   t   Others
   %s%s%s%s%sR   R   (   t   dictRN   R3  R  R6  t   haslayerR   R   t   packetlist_protoR  t   punctt   packetlist_valuet   packetlist_nameR4  (   R   R3  R   Rg   R   Rc   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   	  s8    
  		
 c         C   s   t  |  i |  S(   N(   RD   R  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   	  s    c            s   t   t  oO t  t  o?   i t    f d     i  d d  i   i f Sn t   t	 j o*   i   i i
   d d   i Sn   i i
   S(   Nc            s      i  |   j S(    (   R6  (   R6   (   R   t   item(    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   	  s    R  s
   %s from %ss   mod %s(   R`   R   RQ  R(  R   R"   R  R   R4  t   sliceRF   (   R   RA  (    (   R   RA  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRF   	  s     $c         O   s)   |  i  |  i i | |   d d |  i S(   NR  s   mod %s(   R   R  t   __getslice__R4  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRC  	  s    c         C   s-   |  i  |  i | i d d |  i | i f S(   NR  s   %s+%s(   R   R  R4  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __add__	  s    c         C   sg   x` |  i  D]U } | d j	 o | |  p q
 q5 n | d j o |  i |  GHq
 | |  GHq
 Wd S(   s   prints a summary of each packet
prn:     function to apply to each packet instead of lambda x:x.summary()
lfilter: truth function to apply to each packet to decide whether it will be displayedN(   R  R   R8  (   R   t   prnt   lfilterRg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR7  
  s    
 c         C   s   x t  t |  i   D]} } | d j	 o | |  i |  p q qH n t i i | d  G| d j o |  i |  i |  GHq | |  i |  GHq Wd S(   s   prints a summary of each packet with the packet's number
prn:     function to apply to each packet instead of lambda x:x.summary()
lfilter: truth function to apply to each packet to decide whether it will be displayeds   %04iN(   R   Rq   R  R   R   R   R  R8  (   R   RE  RF  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nsummary
  s     c         C   s   |  i    d S(   s   deprecated. is show()N(   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   
  s    c         O   s   |  i  | |   S(   sB   Best way to display the packet list. Defaults to nsummary() method(   RG  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  
  s    c         C   s&   |  i  t | |  i  d d |  i S(   s2   Returns a packet list filtered by a truth functionR  s   filtered %s(   R   R"   R  R4  (   R   t   func(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"   "
  s    c         O   s   t  |  i | |  S(   s   Prints a table using a function that returs for each packet its head column value, head row value and displayed value
        ex: p.make_table(lambda x:(x[IP].dst, x[TCP].dport, x[TCP].sprintf("%flags%")) (   t
   make_tableR  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRI  &
  s    c         O   s   t  |  i | |  S(   s0   Same as make_table, but print a table with lines(   t   make_lined_tableR  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  *
  s    c         O   s   t  |  i | |  S(   s7   Same as make_table, but print a table with LaTeX syntax(   t   make_tex_tableR  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK  -
  s    c         K   sa   t  i    } |  i } | d j	 o t | |  } n t | |  } | i t  i | |   | S(   s   Applies a function to each packet to get a value that will be plotted with GnuPlot. A gnuplot object is returned
        lfilter: a truth function that decides whether a packet must be plotedN(   t   GnuplotR  R   R"   RN   t   plott   Data(   R   R   RF  RA   t   gR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRM  1
  s    	i   c         K   sm   t  i    } |  i } | d j	 o t | |  } n t | | |  | |  } | i t  i | |   | S(   sZ   diffplot(f, delay=1, lfilter=None)
        Applies a function to couples (l[i],l[i+delay])N(   RL  R  R   R"   RN   RM  RN  (   R   R   t   delayRF  RA   RO  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   diffplot<
  s    	c      	   K   s   t  i    } |  i } | d j	 o t | |  } n h  } xO | D]G } | |  \ } }	 | | j o | | i |	  qB |	 g | | <qB Wg  }
 x1 | D]) } |
 i t  i | | d | |  q W| i |
   | S(   si   Uses a function that returns a label and a value for this label, then plots all the values label by labelt   titleN(   RL  R  R   R"   Rf   RN  RM  (   R   R   RF  RA   RO  R   R   R|   RR   R
  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   multiplotG
  s"    	  'c         C   s(   x! |  D] } t  |  i |   q Wd S(   s5   Prints an hexadecimal dump of each packet in the listN(   R   R6  (   R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   rawhexdump]
  s     c         C   s   x t  t |  i   D] } |  i |  i |  } | d j	 o | |  o q n d t i i | d  | i d  |  i	 |  i |  f GH| i
 t  o t | i t  i  q q Wd S(   s   Same as nsummary(), except that if a packet has a Raw layer, it will be hexdumped
        lfilter: a truth function that decides whether a packet must be displayeds   %s %s %ss   %04is   %.time%N(   R   Rq   R  R6  R   R   R   R  t   sprintfR8  R<  t   RawR   t   getlayerR!  (   R   RF  R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   hexrawb
  s     c         C   s   x t  t |  i   D] } |  i |  i |  } | d j	 o | |  o q n d t i i | d  | i d  |  i	 |  i |  f GHt
 |  q Wd S(   s   Same as nsummary(), except that packets are also hexdumped
        lfilter: a truth function that decides whether a packet must be displayeds   %s %s %ss   %04is   %.time%N(   R   Rq   R  R6  R   R   R   R  RU  R8  R   (   R   RF  R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   o
  s     c         C   s   x t  t |  i   D] } |  i |  i |  } | i t  or | d j p | |  oT d t i i	 | d  | i
 d  |  i |  i |  f GHt | i t  i  q q q Wd S(   s#   Same as hexraw(), for Padding layers   %s %s %ss   %04is   %.time%N(   R   Rq   R  R6  R<  t   PaddingR   R   R   R  RU  R8  R   RW  R!  (   R   RF  R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   padding{
  s     c         C   s   x t  t |  i   D] } |  i |  i |  } | i t  o | i t  i } | | d t |  j o q n | d j p | |  oT d t	 i
 i | d  | i d  |  i |  i |  f GHt | i t  i  q q q Wd S(   s+   Same as padding() but only non null paddingi    s   %s %s %ss   %04is   %.time%N(   R   Rq   R  R6  R<  RY  RW  R!  R   R   R   R  RU  R8  R   (   R   RF  R   Rc   RV  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   nzpadding
  s     c   	      K   s   | d j o d   } n h  } xW |  i D]L } |  i |  } y | |  } Wn
 q* n X| i | d  d | | <q* Wd } x( | D]  \ } } | d | | f 7} q W| d 7} t | |  S(   s  Graphes a conversations between sources and destinations and display it
        (using graphviz and imagemagick)
        getsrcdst: a function that takes an element of the list and return the source and dest
                   by defaults, return source and destination IP
        type: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T" option
        target: filename or redirect. Defaults pipe to Imagemagick's display program
        prog: which graphviz program to usec         S   s   |  t  i |  t  i f S(    (   t   IPRO  R  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    i    i   s   digraph "conv" {
s   	 "%s" -> "%s"
s   }
N(   R   R  R6  R   R   (	   R   t	   getsrcdstRA   t   convRc   R   t   grR   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   conversations
  s"    
  
c            s  | d j o d   } n | d j o d   } n | d j o d   } n h  } h  } h  } x:|  i D]/} y| |  | |  | |  }	 }
 } |	 | j oL | |	 \ } } | d 7} |
 | j o | i |
  n | | f | |	 <n d |
 g f | |	 <|
 | j oL | |
 \ } } | d 7} | | j o | i |  n | | f | |
 <n d | g f | |
 <| i | d  d | | <Wqj qj qj Xqj Wd d k     f d   } d	   } | t d
   | i     \ } } | t d   | i     \ } } | | i    \ } } d } | d 7} xV | D]N }	 | |	 \ } } d t | |  | | } | d |	 |	 | | f 7} q8W| d 7} xZ | D]R }
 | |
 \ } } d t | |  | | } } | d |
 |
 | | f 7} qWxT | D]L } | | } d t | |  | | } } | d | | | | f 7} qW| d 7} xE | D]= }	 | |	 \ } } x$ | D] }
 | d |	 |
 f 7} qvWqYWxE | D]= }
 | |
 \ } } x$ | D] } | d |
 | f 7} qWqW| d 7} t d d  i	 |  t
 | |  S(   s   Experimental clone attempt of http://sourceforge.net/projects/afterglow
        each datum is reduced as src -> event -> dst and the data are graphed.
        by default we have IP.src -> IP.dport -> IP.dstc         S   s   |  t  i S(    (   R\  RO  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    c         S   s   |  t  i S(    (   R\  t   dport(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    c         S   s   |  t  i S(    (   R\  R  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    i   i    iNc            s   d   i  |   d S(   Ni   g      @(   t   log(   R   (   t   math(    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   normalize
  s    c         S   sQ   t  |   t |   } } | | j o
 d } n | d j o
 d } n | | f S(   Ni    i   (   R   R  (   R6   R  t   M(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   minmax
  s    

c         S   s   |  \ } } | S(    (    (   RI   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    c         S   s   |  \ } } | S(    (    (   RI   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    s'   digraph "afterglow" {
	edge [len=2.5];
s   # src nodes
sl   "src.%s" [label = "%s", shape=box, fillcolor="#FF0000", style=filled, fixedsize=1, height=%.2f,width=%.2f];
s   # event nodes
sp   "evt.%s" [label = "%s", shape=circle, fillcolor="#00FFFF", style=filled, fixedsize=1, height=%.2f, width=%.2f];
sr   "dst.%s" [label = "%s", shape=triangle, fillcolor="#0000ff", style=filled, fixedsize=1, height=%.2f, width=%.2f];
s   ###
s    "src.%s" -> "evt.%s";
s    "evt.%s" -> "dst.%s";
R   s   /tmp/azeR   (   R   R  Rf   R   Rc  RN   RO  t   floatRl   R   R   (   R   RO  t   eventR  RA   t   slt   elt   dlR   R   R|   R   R   R   Rd  Rf  t   minst   maxst   minet   maxet   mindt   maxdR_  (    (   Rc  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   afterglow
  s    
 &

	$$
 , 
 0  * 
    
c   
   	      s   t   f d    i  } t  f d   |  } g    xd | D]\ } | i t  i } xA | D]9 } | d d j o"   i | i | d d f  q_ q_ Wq@ W  p t d  d Sn t    f d      } t	 i	   }	 |	 i
 t	 i | |   |	 S(	   sO   Tries to graph the timeskew between the timestamps and real time for a given ipc            s     i  |   S(    (   R6  (   R6   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c            s6   |  i  t  o& |  i t  i   j o |  i  t  S(    (   R<  R\  RW  RO  R0  (   R6   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    i    t	   Timestampi   s"   No timestamps found in packet listNc            s:   |  \ } } | d  |   d d |   d d d f S(   i  i    i   g     @@(    (   RI   R6   RJ   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   RN   R  R"   RW  R0  R   Rf   R   R   RL  RM  RN  (
   R   R   RA   R  R  Rc   t   optsRb   R   RO  (    (   R   R   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   timeskew_graph   s"      *
c      
   K   s  t  i i   } t |  i  } x t t |  i   D] } |  i | } |  i |  i |   } | i   } | i | i	   | i
   d d | | f t  i i i g  t i d j o t i d d  n | i t  i i | d t  i i i d d t  i i d d  q4 W| S(   Ni   s+   \font\cmssfont=cmss12\cmssfont{Frame %i/%i}i   R   t   paperformatt   margint	   fittosize(   t   pyxt   documentRq   R  R   R6  t   canvas_dumpt   bboxR  R   R  R:  t   LARGER   R  R   R   Rf   t   pageRv  t   A4t   unitt   t_cm(   R   RA   R   R   R   R5  R   t   cbb(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _dump_document  s     <$c         K   sl   |  i  |   } | d j o> d t i   } | i |  t i d t i i | f  n | i |  Hd S(   s   Creates a multipage poscript file with a psdump of every packet
        filename: name of the file to write to. If empty, a temporary file is used and
                  conf.prog.psreader is calleds   /tmp/scapy.psd.%is
   %s %s.ps &N(	   R  R   R   t   getpidt   writePSfileRN  R   R   t   psreader(   R   Rw   RA   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   psdump#  s    !c         K   sl   |  i  |   } | d j o> d t i   } | i |  t i d t i i | f  n | i |  Hd S(   s   Creates a PDF file with a psdump of every packet
        filename: name of the file to write to. If empty, a temporary file is used and
                  conf.prog.pdfreader is calleds   /tmp/scapy.psd.%is   %s %s.pdf &N(	   R  R   R   R  t   writePDFfileRN  R   R   t	   pdfreader(   R   Rw   RA   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   pdfdump0  s    !i    c         C   s  |  i  } g  } d } x | t |  j  o | | } | } x | t |  d j  o | d 7} | | } | i |  oX | i | | f  | o! d | | _ d | | _ q? n | | =| | =| d 8} Pq? q? W| d 7} q W| o t d   |  } n t |  t |  f S(   s   sr([multi=1]) -> (SndRcvList, PacketList)
        Matches packets in the list and return ( (matched couples), (unmatched packets) )i    i   i   c         S   s   t  |  d   S(   t	   _answered(   RM  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   U  s    (   R  Rq   t   answersRf   R  R"   t
   SndRcvListR%  (   R   t   multiR  t   srR   R   R   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  =  s.    





N($   R   R   R  R   R   R6  R8  R9  RV   R   RF   RC  RD  R7  RG  R   R  R"   RI  RJ  RK  RM  RQ  RS  RT  RX  R   RZ  R[  R`  Rr  Ru  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%  	  sB   															R		t   Dot11PacketListc           B   s#   e  Z d d  d d  Z d   Z RS(   t	   Dot11Listc         C   s@   | d  j o t t t t t g } n t i |  | | |  d  S(   N(   R   t   Dot11WEPt   Dot11BeaconR1  R2  R0  R%  R   (   R   R  R  R3  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   ^  s    c         C   s   t  d   t d   |  i   } g  } xA | D]9 } | i   } | i   | i t   | i i i  q. Wt | d d |  i	 S(   Nc         S   s   |  i  t  S(    (   RW  t   Dot11(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   d  s    c         S   s   |  i  t  o |  i d  j S(   i   (   R<  R  R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   d  s    R  s   Ether from %s(
   RN   R"   R  R  t   unwepRf   R  R  R%  R4  (   R   R  t   r2Rc   t   q(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   toEthernetc  s    ! 
!N(   R   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ]  s   R  c           B   s,   e  Z d d  d d  Z d   Z d   Z RS(   t   Resultsc         C   s   t  i |  | | |  d  S(   N(   R%  R   (   R   R  R  R3  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   o  s    c         C   s   | d S(   Ni   (    (   R   R5  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR6  q  s    c         C   s"   d | d i    | d i    f S(   Ns	   %s ==> %si    i   (   R7  (   R   R5  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR8  s  s    N(   R   R   R   R   R6  R8  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  n  s   	t   ARPingResultc           B   s#   e  Z d d  d d  Z d   Z RS(   t   ARPingc         C   s   t  i |  | | |  d  S(   N(   R%  R   (   R   R  R  R3  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   x  s    c         C   s,   x% |  i  D] \ } } | i d  GHq
 Wd  S(   Ns   %Ether.src% %ARP.psrc%(   R  RU  (   R   R   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  {  s    
 N(   R   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  w  s   t   AS_resolverc           B   sS   e  Z d Z d  Z d d d d  Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s   -ki+   c         C   sA   | d  j	 o | |  _ n | |  _ | d  j	 o | |  _ n d  S(   N(   R   t   servert   portR   (   R   R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
    	c         C   sp   t  i  t  i t  i  |  _ |  i i |  i |  i f  |  i o+ |  i i |  i d  |  i i	 d  n d  S(   Ns   
i    (
   R4   RZ  t   SOCK_STREAMR   t   connectR  R  R   t   sendRJ  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _start  s
    
c         C   s   |  i  i   d  S(   N(   R   R~   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _stop  s    c         C   s   d \ } } x | i   D] } | o$ | i d  o | d i   } n | i d  o- | o | d 7} n | | d i   7} n | d  j	 o | o Pq q W| | i   f S(   NR   s   origin:i   s   descr:s   \ni   (   NR   (   R   t
   splitlinesR   Rn   (   R   t   txtt   asnt   descR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _parse_whois  s     	c         C   st   |  i  i d |  d } x5 d | j p
 d | j p | |  i  i d  7} q W|  i |  \ } } | | | f S(   Ns   %s
R   R   t   sourcei    (   R   R  RJ  R  (   R   R   R6   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _resolve_one  s    c         G   sn   |  i    g  } xM | D]E } |  i |  \ } } } | d  j	 o | i | | | f  q q W|  i   | S(   N(   R  R  R   Rf   R  (   R   t   ipsR  R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   resolve  s    
 
N(   R   R   R   R  R   R   R  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   				t   AS_resolver_riswhoisc           B   s   e  Z d  Z d Z RS(   s   riswhois.ripe.nets   -k -M -1(   R   R   R  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   AS_resolver_radbc           B   s   e  Z d  Z d Z RS(   s   whois.ra.nets   -k -M(   R   R   R  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   AS_resolver_cymruc           B   s   e  Z d  Z d Z d   Z RS(   s   whois.cymru.comc   	      G   s#  g  } t  i  t  i t  i  } | i |  i |  i f  | i d d i |  d  d } x. | i d  } | d j o Pn | | 7} q^ | i	   x | i
   d D]t } d | j o q n t t i | i d   \ } } } | d j o q n t |  } | i | | | f  q W| S(	   Ns   begin
s   
s   
end
R   i    i   R   t   NA(   R4   RZ  R  R  R  R  R  RU   RJ  R~   R  RN   R   Rn   Rp   Rr   Rf   (	   R   R  t   ASNlistR   Rg   R   R  R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s*    
 $N(   R   R   R  R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   AS_resolver_multic           B   s2   e  Z e   e   e   f Z d    Z d   Z RS(   c         G   s   | o | |  _  n d  S(   N(   t   resolvers_list(   R   t   reslist(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         G   s   | } g  } x |  i  D]{ } | i |   } g  } | D] \ } } }	 | | q6 ~ }
 g  } | D] } | |
 j o | | q` q` ~ } | | 7} q W| S(   N(   R  R  (   R   R  t   todoR  t   ASresR  R  R   R  R  t   resolvedRJ  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
 *2(   R   R   R  R  R  R  R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	t   TracerouteResultc           B   s\   e  Z d	 d  d	 d  Z d   Z d   Z d   Z d   Z d	 d d  Z d	 d d  Z	 RS(
   t
   Traceroutec         C   sG   t  i |  | | |  d  |  _ d |  _ d |  _ d  |  _ d  |  _ d  S(   Ni    (   R%  R   R   t   graphdeft
   graphASresRZ  t   hloct   nloc(   R   R  R  R3  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    				c         C   s   |  i  d    S(   Nc         S   s.   |  \ } } | i  d   | i | i  d  f S(   sB   %IP.dst%:{TCP:tcp%ir,TCP.dport%}{UDP:udp%ir,UDP.dport%}{ICMP:ICMP}s4   %-15s,IP.src% {TCP:%TCP.flags%}{ICMP:%ir,ICMP.type%}(   RU  RQ  (   RI   R   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s   (   RI  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c            s  h  } x{ |  i  D]p \ } } t | j o q n | t i } | | j o h  | | <n | t i t | j f | | | t i <q Wx{ | i   D]m   t   f d     i    } | p q n t	 |  } x,   i   D] } | | j o   | =q q Wq W| S(   Nc            s     |  d  S(   i   (    (   R6   (   RR   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (
   R  R\  R  RO  R2  RQ  RO  R"   RQ   R   (   R   t   traceR   Rg   R   R  R   (    (   RR   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   get_trace  s(    
 ,  c            sR  |  i    } d d k   d   i f   f d     Y}   i     _   i i d    i   } h  } h  } x | D] } | | } g  | | <| i   } x t d t	 |  d  D] }	 |	 | j o g  | |	 <n |	 | j oT | |	 | |	 j o | |	 i
 | |	  n | | i
 | |	 i | |	   q | |	 i
 d$  | | i
 t | |	  d  q Wqu WxJ| D]B}	 | |	 }
 t |
  } x#t |  D]} |
 | d d j o
 d% } n, |
 | d o   i i } n   i i } | d	 | d   i d
 |   i |  | d   i d
 |   i |  d
 |	 f d |
 | d d |  } xR | i   D]D } |	 t |  j o+ | |	 d | j o | | |	 d <qqlqlWqWqvWt d d d d  } xi | i   D][ } | i   } d& } x@ | D]8 }   i d	 | d | i | d | d d  | i } qWqWd } x  i i i o(   i i i   } | d j o Pq~n   i i i o  i i i   } | i d j o'| i } | o| i  o | i! d j o qFn | i } d' | _ t" t# d | i!  t$ d d d d d d d g  d d
 \ } } | | _ t |  d j o d | i! } n8 d  | i! } x' | D] \ } }
 | |
 i% d!  7} qwW| i& | d" d qt' | d#  o | i(   qqq| i) d j o | i } q| i* d j o
 d } qn | o2   i i+   i i i | 8_+   i i i } qFqFd S((   s#  Give a 3D representation of the traceroute.
        right button: rotate the scene
        middle button: zoom
        left button: move the scene
        left button on a ball: toggle IP displaying
        ctrl-left button on a ball: scan ports 21,22,23,25,80 and 443 and display the resultiNt   IPspherec              s2   e  Z   f d    Z d   f d  Z d   Z RS(   c            s9     i  i |  |  | |  _ d  |  _ |  i |  i  d  S(   N(   t   sphereR   R   R   R   t   setlabel(   R   R   RA   (   t   visual(    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    		c            s   |  i  d  j	 o- | d  j o |  i  i } n d |  i  _ n | d  j o
 d } n   i  d | d |  i d |  i d d d d d	 |  |  _  d  S(
   Ni    R  t   post   spacet   xoffseti
   t   yoffseti   t   visible(   R   R   R  R  t   radius(   R   R  R  (   R  (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
c         S   s   |  i  i d N_ d  S(   Ni   (   R   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   action  s    N(   R   R   R   R   R  R  (    (   R  (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   i    i   t   unkg      ?R  i   R   t   colorg      ?g      ?g      ?g      ?t   axisR  g?t   escR   R  Ra  i   i   i   i   iP   i  R  s   %s:
no resultss   %s:
sh   {TCP:%IP.src%:%TCP.sport% %TCP.flags%}{TCPerror:%IPerror.dst%:%TCPerror.dport% %IP.src% %ir,ICMP.type%}
R  R  (   R  i(   g      ?g      ?g      ?(   i    i    i    (   i   i    i    (,   R  R  R  R   t   scenet   exit_on_closet   boxRQ   R   R  Rf   RS  Rq   R  t   greent   bluet   cost   pit   sinRO  R   R   t   cylinderR  R   t   kbt   getkeyt   mouset   eventst   geteventt   presst   pickt   ctrlR   R  R\  R0  RU  R  RM  R  t   dragt   dropt   center(   R   R  R  R   t   ringst   tr3dR   t   trRQ  RT  Rg   R   R   R   t   trlstt   forecolR   t	   movcenterRR   t   evRb   t   savcolorR  R  R  (    (   R  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   trace3D  s     

 &' 
 
Y	 "  )		
		C	 c         C   s<  h  } h  } h  } x%|  i  D]\ } } d  | | i <| i t  p | i t  o" | i | i | i | i f } nN | i t	  o" | i | i | i | i
 f } n | i | i | i d f } | i | h   } | i t	  p | i
 d j o% | i |  o q n d  | | <n | i | | i <| | | <q Wh  } x | D] } | | } g  }	 xs t t | i     D]Y }
 | i |
 d   } | d  j o qvn t |  } | d  j o qvn |	 i |  qvW|	 o |	 | | <qGqGWt d   | i    } t i   } t i t i d d } | i | |  | S(   Ni    i   c         S   s   t  i |  d  d S(   t   withR  (   RL  RN  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R  R  (   R  R   RO  R<  R0  R1  R  t   protoRa  R2  R   R   R  RQ  R   R  RQ   t	   locate_ipRf   RN   RO  RL  t   FileR   t   gnuplot_worldRM  (   R   R  R`  t
   ports_doneR   Rg   t   trace_idR  t   trtt   loctraceR   R   t   locR  RO  t   world(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   world_tracet  sN    
  ""! 
 i    c   "      C   s  | d  j o t i } n | |  _ | |  _ h  } h  } h  } h  } x|  i D]\ } } | t p | t p | } | t p | t p | } d  | | i <t	 | j o | i | i
 d | i f }	 nt t | j o | i | i
 d | i f }	 nH t | j o | i | i
 d | i f }	 n | i | i
 | i d f }	 | i |	 h   }
 t | j o
 | i p | i } t | j o | t i d j o6t | j o
 t | j o|	 | j o qN n d  | |	 <| i | i g   } t	 | j o- | i | i d   | i d  |
 | <n t | j o- | i | i d   | i d	  |
 | <nd t | j o- | i | i d
   | i d  |
 | <n* | i | i d   | i d  |
 | <| | | i <n | i d  |
 | <|
 | |	 <qN Wt d  } g  } h  } xd| D]\} | | }
 |
 i   } xG t t |  t |   D]* } |
 i |  p | i   |
 | <q@q@W| i |  p | d d j o d | d | d f } ns | d d j o d | d | d f } nF | d d j o d | d | d f } n d | d | d f } d  | | <| | | d <d | } | |
 t |  d <| i |  qqWt i t d   |   i   } | d  j o
 g  } n | i  |   } h  } h  } x | D] \ } } } | d  j o qn | i | g   } | | j o3 | | j o | i |  n | i | |  n | i |  | | | <| | | <qWt! d d d d  } t! d d d d  } d  } | d! 7} | d" 7} x | D] } | d# | 7} | i   } | d$ | 7} | d% | 7} | d& 7} | d' | | | f 7} x  | | D] } | d( | 7} qW| d) 7} qW| d* 7} x2 | D]* } | d+ | | d, i" | |  f 7} qGW| d- 7} x | D] } | d. | 7} qW| o | d/ 7} h  } xu |  i D]j \ }  }! |! i | j oN |! i# t$  o> |! i% t$  i& } | d0 t' |  j o d  | |! i <q)qqWx  | D] }! | d1 |! 7} q4Wn | d! 7} x | D] } | d2 | 7} | d3 | i   7} | | }
 |
 i   } x5 t t |  t |   D] } | d4 |
 | 7} qW| d5 |
 t |  7} qaW| d6 7} | |  _( d  S(7   Ni   i   i   i    i   s)   <T%ir,TCP.sport%> %TCP.sport% %TCP.flags%s   "%r,src%":T%ir,TCP.sport%s   <U%ir,UDP.sport%> %UDP.sport%s   "%r,src%":U%ir,UDP.sport%s"   <I%ir,ICMP.type%> ICMP %ICMP.type%s   "%r,src%":I%ir,ICMP.type%s8   {IP:<P%ir,proto%> IP %proto%}{IPv6:<P%ir,nh%> IPv6 %nh%}s)   "%r,src%":{IP:P%ir,proto%}{IPv6:P%ir,nh%}s	   "%r,src%"s   unk%ii   s
   %s %i/icmpi   s	   %s %i/tcps	   %s %i/udps   %s %i/protos   "%s"c         S   s   |  i  d  d  d S(   RT   i   i    (   t   rsplit(   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    t   60t   86t   bat   fft   a0t   70t   40t   20s   digraph trace {
s1   
	node [shape=ellipse,color=black,style=solid];

s   
#ASN clustering
s   	subgraph cluster_%s {
s   		color="#%s%s%s";s*   		node [fillcolor="#%s%s%s",style=filled];s   		fontsize = 10;s   		label = "%s\n[%s]"
s   		"%s";
s   	}
s   #endpoints
sM   	"%s" [shape=record,color=black,fillcolor=green,style=filled,label="%s|%s"];
R   s   
#Blackholes
s<   	%s [shape=octagon,color=black,fillcolor=red,style=filled];
s
   
#Padding
Rh   s?   	"%s" [shape=triangle,color=black,fillcolor=red,style=filled];
s   #---[%s
s   		edge [color="#%s%s%s"];
s   	%s ->
s   	%s;
s   }
()   R   R   R  R  t   graphpaddingR  R\  t   IPv6RO  R0  R  Ra  R1  R2  R   R  R   t   hlimRQ  t   ICMPv6TimeExceededRf   RU  R   RQ   R   R   R  R  R   R;  t   fromkeysRN   R  R   RU   R<  RY  RW  R!  Rq   R  ("   R   R  RZ  R  R`  t   portsR  R   Rg   R  R  RQ  Rc   t   unknown_labelt
   blackholest   bhipt   rtkRR   R   t   bht   ASN_query_listR  t   ASNst   ASDsR   R  R  t   iplistt   backcolorlistt   forecolorlistR   RV  t   sndt   rcv(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   make_graph  s
   		
  =
 
 

!
 


 
 
 (
 

   
 
 
c         K   sn   | d j o t i } n |  i d j p  |  i | j p |  i | j o |  i | |  n t |  i |  S(   s  x.graph(ASres=conf.AS_resolver, other args):
        ASres=None          : no AS resolver => no clustering
        ASres=AS_resolver() : default whois AS resolver (riswhois.ripe.net)
        ASres=AS_resolver_cymru(): use whois.cymru.com whois database
        ASres=AS_resolver(server="whois.ra.net")
        type: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T" option
        target: filename or redirect. Defaults pipe to Imagemagick's display program
        prog: which graphviz program to useN(   R   R   R  R  R  R  R  R   (   R   R  RZ  RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   6  s    	N(
   R   R   R   R   R  R  R  R  R  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   			m	*t   Fieldc           B   s   e  Z d  Z d Z d Z d 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   For more informations on how this work, please refer to
       http://www.secdev.org/projects/scapy/files/scapydoc.pdf
       chapter ``Adding a New Field''i    R/   c         C   sk   | |  _  | d d j o | |  _ n d | |  _ |  i d  |  |  _ t i |  i  |  _ g  |  _ d  S(   Ni    s   @=<>!t   !(	   R  RE  t   any2iR   R  R   t   calcsizet   szt   owners(   R   R  R  RE  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   U  s    	c         C   s   |  i  i |  d  S(   N(   R  Rf   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   register_owner_  s    c         C   s   |  i  S(   s<   Convert internal value to a length usable by a FieldLenField(   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   i2lenb  s    c         C   s   d S(   sq   Convert internal value to a number of elements usable by a FieldLenField.
        Always 1 except for list fieldsi   (    (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   i2counte  s    c         C   s   | S(   s%   Convert human value to internal value(    (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   h2ii  s    c         C   s   | S(   s%   Convert internal value to human value(    (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   i2hl  s    c         C   s   | S(   s'   Convert machine value to internal value(    (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   m2io  s    c         C   s   | d j o
 d } n | S(   s'   Convert internal value to machine valuei    N(   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   i2mr  s    
c         C   s   |  i  | |  S(   sU   Try to understand the most input values possible and make an internal value from them(   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  w  s    c         C   s-   | d j o
 d } n t |  i | |   S(   s/   Convert internal value to a nice representationi    N(   R   R  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   i2reprz  s    
c         C   s#   | t  i |  i |  i | |   S(   s"   Add an internal value  to a string(   R   R   RE  R!  (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   addfield  s    c         C   s7   | |  i  |  i | t i |  i | |  i    d  f S(   s'   Extract an internal value from a stringi    (   R  R   R   R   RE  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   getfield  s    c         C   s   t  | d  o | i   Sn t |  t j oT | } xJ t t |   D]2 } t | | t  o | | i   | | <qK qK Wn | S(   NR  (   RM  R  R   R   R  Rq   R`   R(  (   R   R6   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   do_copy  s      c         C   s'   d d i  d   |  i D  |  i f S(   Ns   <Field (%s).%s>t   ,c         s   s   x |  ] } | i  Vq Wd  S(   N(   R   (   RI   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pys	   <genexpr>  s    (   RU   R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    c         C   s   t  i |   S(   N(   R  t   deepcopy(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   |  i  d } | d j o3 h  t d <t d <t d <t d <|   Snw | d j oO |  i  d d	 j o t |  i  d   } n t |  i  d
 d ! } t |  Sn t d |  i |  i  f  d S(   sO   Return a volatile object whose value is both random and suitable for this fieldit   BHIQRj  R/   R  t   QR   i    R7   i   s"   no random class for [%s] (fmt=%s).N(	   RE  R-  R.  R/  R1  Rr   R;  R   R  (   R   t   fmttR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    3(   R   R   RW  t   islistt   holds_packetsR   R  R  R  R  R  R   R!  R  R"  R#  R$  R%  RV   R  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  O  s&   
															t   Emphc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   R   c         C   s   | |  _  d  S(   N(   t   fld(   R   R.  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  |  i |  S(   N(   RD   R.  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  |  i  S(   N(   t   hashR.  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __hash__  s    c         C   s   |  i  | j S(   N(   R.  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R.  R   R   R0  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR-    s
   			t   ActionFieldc           B   s)   e  Z d Z d    Z d   Z d   Z RS(   c         K   s   | |  _  | |  _ | |  _ d  S(   N(   t   _fldt   _action_methodt	   _privdata(   R   R.  t   action_methodRA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    		c         C   s;   t  | |  i  | |  i |  i  t  |  i d  | |  S(   NR  (   RD   R3  R2  R4  (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    "c         C   s   t  |  i |  S(   N(   RD   R2  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    N(   R   R   R   R2  R   R  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR1    s   		t   ConditionalFieldc           B   s;   e  Z d Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   R.  t   cond(   R   R.  R7  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   s   |  i  |  S(   N(   R7  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   _evalcond  s    c         C   s5   |  i  |  o |  i i | |  Sn | d  f Sd  S(   N(   R8  R.  R$  R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    c         C   s2   |  i  |  o |  i i | | |  Sn | Sd  S(   N(   R8  R.  R#  (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#    s    c         C   s   t  |  i |  S(   N(   RD   R.  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    N(	   R   R   R   R.  R   R8  R$  R#  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR6    s   				t   PadFieldc           B   s2   e  Z d  Z d Z d d  Z d   Z d   Z RS(   sg   Add bytes after the proxified field so that it ends at the specified
       alignment from its beginingc         C   s&   | |  _  | |  _ | p d |  _ d  S(   NR   (   R2  t   _alignt   _padwith(   R   R.  t   alignt   padwith(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    		c         C   sE   |  i  i | d |  } | | t i d t |  |  i |  i  S(   NR   s   %is(   R2  R#  R   R   Rq   R:  R;  (   R   R   R   RB   t   sval(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#    s    c         C   s   t  |  i |  S(   N(   RD   R2  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    N(   R   R   RW  R   R2  R   R#  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR9    s
   	t   MACFieldc           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s   t  i |  | | d  d  S(   Nt   6s(   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   | d  j o d Sn t |  S(   NR  (   R   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    c         C   s
   t  |  S(   N(   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s@   t  |  t j o) t |  d j o |  i | |  } n | S(   Ni   (   R   R   Rq   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    &c         C   s<   |  i  | |  } |  t i j o t i i |  } n | S(   N(   R  R   R  R   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    c         C   s   t    S(   N(   RA  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   R   R!  R   R  R"  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR?    s   					t   DestMACFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  i |  | d   d  S(   N(   R?  R   R   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s*  | d  j o
d  } t | i t  o | i i } nG t | i t  o | i i } n$ t | i t  o | i i } n t | t  o | i	   i
   } n | d  j	 o? t | i t  o t | d d } q t | d d } n | d  j o d } t d |  qn t i |  | |  S(   NR  i   s   ff:ff:ff:ff:ff:ffs"   Mac address to reach %s not found
(   R   R`   R  R  R  R\  R  R  R!  RP   R   t   getmacbyip6R  R   R?  R  (   R   R   R6   t   dstip(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s$    c         C   s   t  i |  | |  i | |   S(   N(   R?  R!  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    (   R   R   R   R  R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRA    s   		t   SourceMACFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  i |  | d   d  S(   N(   R?  R   R   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sH  | d  j o(d  } t | i t  o | i i } nG t | i t  o | i i } n$ t | i t  o | i i } n t | t  o | i	   i
   } n | d  j	 o t | i t  o t i i |  \ } } } n t i i |  \ } } } y t |  } Wn n X| d  j o
 d } q1q5n t i |  | |  S(   Ns   00:00:00:00:00:00(   R   R`   R  R  R  R\  R  R  R!  RP   R   R   t   route6Rf  R  R?  R  (   R   R   R6   RC  Rs  R  t   nhRc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s*    c         C   s   t  i |  | |  i | |   S(   N(   R?  R!  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  -  s    (   R   R   R   R  R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRD    s   		t   ARPSourceMACFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  i |  | d   d  S(   N(   R?  R   R   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   1  s    c         C   s   | d  j o | i } t | t  o | i   i   } n | d  j	 oP t i i |  \ } } } y t |  } Wn n X| d  j o
 d } q q n t	 i
 |  | |  S(   Ns   00:00:00:00:00:00(   R   R  R`   R!  RP   R   R   Rf  R  R?  R  (   R   R   R6   RC  Rs  R  Rc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  3  s    	c         C   s   t  i |  | |  i | |   S(   N(   R?  R!  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  A  s    (   R   R   R   R  R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRG  0  s   		t   Dot11AddrMACFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   d S(   Ni   (    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   is_applicableE  s    c         C   s2   |  i  |  o t i |  | | |  Sn | Sd  S(   N(   RI  R?  R#  (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#  G  s    c         C   s5   |  i  |  o t i |  | |  Sn | d  f Sd  S(   N(   RI  R?  R$  R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  L  s    (   R   R   RI  R#  R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRH  D  s   		t   Dot11Addr2MACFieldc           B   s   e  Z d    Z RS(   c         C   s%   | i  d j o | i d j Sn d S(   Ni   i   i
   i   i   (   i   i
   i   i   (   R   t   subtype(   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRI  S  s    (   R   R   RI  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  R  s   t   Dot11Addr3MACFieldc           B   s   e  Z d    Z RS(   c         C   s   | i  d j o d Sn d S(   Ni    i   i   (   i    i   (   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRI  Y  s    (   R   R   RI  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRL  X  s   t   Dot11Addr4MACFieldc           B   s   e  Z d    Z RS(   c         C   s4   | i  d j o  | i d @d j o d Sq0 n d S(   Ni   i   i   i    (   R   t   FCfield(   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRI  _  s    (   R   R   RI  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRM  ^  s   t   IPFieldc           B   sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   s   t  i |  | | d  d  S(   Nt   4s(   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   f  s    c         C   s   t  |  t j o7 y t |  Wq t i j
 o t |  } q XnE t  |  t j o1 g  } | D] } | |  i | |  qh ~ } n | S(   N(   R   R   R5   R4   R   R?  R   R  (   R   R   R6   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  h  s    1c         C   sH   |  t  i j o4 y t i |  d } Wn qD X| o | SqD n | S(   Ni    (   R   R  R4   t   gethostbyaddr(   R   R6   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  q  s    c         C   s
   t  |  S(   N(   R5   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  {  s    c         C   s
   t  |  S(   N(   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   }  s    c         C   s   |  i  | |  S(   N(   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   |  i  |  i | |   S(   N(   R  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    c         C   s   t    S(   N(   R>  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (
   R   R   R   R  R  R!  R   R  R"  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRO  e  s   				
				t   SourceIPFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s    t  i |  | d   | |  _ d  S(   N(   RO  R   R   t   dstname(   R   R  RS  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sK   | d  j o+ t i i t | |  i   \ } } } n t i |  | |  S(   N(   R   R   Rf  RD   RS  RO  R!  (   R   R   R6   Rs  Rc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    +c         C   s   | d  j o t | |  i  } t | t  ob t t i i |  } | i   | d | d j o | d d } q t	 d t
 |   d  Sq t i i |  \ } } } n t i |  | |  S(   Ni    ii   s#   More than one possible route for %s(   R   RD   RS  R`   R!  RN   R   Rf  RR  R   R  RO  R  (   R   R   R6   R  Rg   Rs  Rc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
(   R   R   R   R!  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRR    s   		t	   ByteFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   NRj  (   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRT    s   t
   XByteFieldc           B   s   e  Z d    Z RS(   c         C   s-   | d  j o
 d } n t |  i | |   S(   Ni    (   R   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    
(   R   R   R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRU    s   t   X3BytesFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  i |  | | d  d  S(   Ns   !I(   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s*   | t  i |  i |  i | |   d d !S(   Ni   i   (   R   R   RE  R!  (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#    s    c      	   C   s5   | d |  i  | t i |  i d | d   d  f S(   Ni   Rh   i    (   R   R   R   RE  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    (   R   R   R   R#  R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV    s   		t
   ShortFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   NR/   (   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRW    s   t   LEShortFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   Ns   <H(   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRX    s   t   XShortFieldc           B   s   e  Z d    Z RS(   c         C   s-   | d  j o
 d } n t |  i | |   S(   Ni    (   R   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    
(   R   R   R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRY    s   t   IntFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   NR  (   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRZ    s   t   SignedIntFieldc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  i |  | | d  d  S(   NR   (   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t    S(   N(   R0  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   R   R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR[    s   	t
   LEIntFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   Ns   <I(   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s   t   LESignedIntFieldc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  i |  | | d  d  S(   Ns   <i(   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t    S(   N(   R0  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   R   R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR]    s   	t	   XIntFieldc           B   s   e  Z d    Z RS(   c         C   s-   | d  j o
 d } n t |  i | |   S(   Ni    (   R   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    
(   R   R   R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR^    s   t	   LongFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   NR)  (   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR_    s   t
   XLongFieldc           B   s   e  Z d    Z RS(   c         C   s-   | d  j o
 d } n t |  i | |   S(   Ni    (   R   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    
(   R   R   R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR`    s   t   IEEEFloatFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   NR   (   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRa    s   t   IEEEDoubleFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   NR   (   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRb    s   c      
   C   s}   yI xB t  i   d g D]- } | \ } } } } | i d  o Pq q WWn d \ } } n Xt i d |  | | f  d  S(   Ns   ??iR   t   fields_descsS   Deprecated use of %s (%s l. %i). See http://trac.secdev.org/scapy/wiki/LengthFields(   s   ??iNR   (   s   ??i(   R   R   R   R   Rt   R   (   R6   t   tbR   R   RL   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt#   FIELD_LENGTH_MANAGEMENT_DEPRECATION  s     t   StrFieldc           B   sG   e  Z d  d d d  Z d   Z d   Z d   Z d   Z d   Z RS(   R/   i    c         C   sM   t  i |  | | |  | |  _ | |  _ | d j o t |  i i  n d  S(   Ni    (   R  R   R  t   shiftRe  R   R   (   R   R  R  RE  R  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
    		c         C   s   t  |  |  i S(   N(   Rq   Rg  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s>   | d  j o
 d } n$ t |  t j	 o t |  } n | S(   NR   (   R   R   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s
    
c         C   s   | |  i  | |  S(   N(   R!  (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#  	  s    c         C   sT   |  i  d j o d |  i | |  f Sn' | |  i  |  i | | |  i    f Sd  S(   Ni    R   (   R  R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    c         C   s   t  t d d   S(   Ni    i  (   R;  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   R   R  R!  R#  R$  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRf    s   				t   PacketFieldc           B   s8   e  Z d  Z d d d  Z d   Z d   Z d   Z RS(   i   i    c         C   s,   t  i |  | | d | d | | |  _ d  S(   NR  Rg  (   Rf  R   R  (   R   R  R  R  R  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s
   t  |  S(   N(   R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    c         C   s   |  i  |  S(   N(   R  (   R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sW   |  i  | |  } d } | i t  o% | i t  } | i ` | i } n | | f S(   NR   (   R   R<  RY  RW  t
   underlayerR  R!  (   R   R   R   R   R  Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    	(   R   R   R,  R   R!  R   R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRh    s
   		t   PacketLenFieldc           B   s)   e  Z d  Z d d d d  Z d   Z RS(   i   i    c         C   si   t  i |  | | | d | | |  _ | d  j	 p | d j o& t |  i i  | | d  |  _ n d  S(   NRg  i    c         S   s   t  |  |  | S(    (   RD   (   R   R.  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   ,  s    (   Rh  R   t   length_fromR   Re  R   R   t
   count_from(   R   R  R  R  R.  Rk  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   '  s
    	c         C   s3   |  i  |  } |  i | | |   } | | | f S(   N(   Rk  R   (   R   R   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  -  s    N(   R   R   R,  R   R   R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRj  %  s   t   PacketListFieldc           B   s_   e  Z d  Z d  Z d	 d	 d	 d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(
   i   i    c         C   s   | d  j o
 g  } n t i |  | | | d | | |  _ | |  _ | d  j	 p | d j o t |  i i  n | d  j	 o | | d  |  _ n d  S(   NRg  i    c         S   s   t  |  |  | S(    (   RD   (   R   R.  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   @  s    (   R   Rh  R   Rl  Rk  Re  R   R   (   R   R  R  R  R.  Rl  Rk  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   6  s    
		c         C   s&   t  |  t j	 o | g Sn | Sd  S(   N(   R   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  B  s    c         C   s%   t  |  t j o t |  Sn d S(   Ni   (   R   R   Rq   (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  G  s    c         C   s   t  d   | D  S(   Nc         s   s   x |  ] } t  |  Vq Wd  S(   N(   Rq   (   RI   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pys	   <genexpr>L  s    (   R   (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  K  s    c         C   s   t  d   |  S(   Nc         S   s
   |  i    S(    (   R  (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   N  s    (   RN   (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%  M  s    c   
      C   s$  d  } } |  i d  j	 o |  i |  } n$ |  i d  j	 o |  i |  } n g  } d } | } | d  j	 o | |  | | } } n x | o | d  j	 o  | d j o Pn | d 8} n |  i | |  } t | j o  | t }	 |	 i } |	 i ` n d } | i |  q W| | | f S(   NR   i    i   (	   R   Rk  Rl  R   RY  R!  Ri  R  Rf   (
   R   R   R   R   R   R  R  R  Rc   RV  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  O  s.    


	c         C   s   | d i  t t |   S(   NR   (   RU   RN   R   (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#  i  s    N(   R   R   R+  R,  R   R   R  R  R  R%  R$  R#  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRm  3  s   					t   StrFixedLenFieldc           B   s5   e  Z d d d  d  Z d   Z d   Z d   Z RS(   i    c         C   sF   t  i |  | | d | | |  _ | d  j	 o | d  |  _ n d  S(   NRg  c         S   s   | S(    (    (   R   t   length(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   r  s    (   Rf  R   Rk  R   (   R   R  R  Ro  Rk  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   n  s    	c         C   s-   |  i  |  } | | |  i | | |   f S(   N(   Rk  R   (   R   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  s  s    c         C   s3   |  i  |  } | t i d | |  i | |   S(   Ns   %is(   Rk  R   R   R!  (   R   R   R   RB   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#  v  s    c         C   s6   y |  i  d   } Wn t d d  } n Xt |  S(   Ni    i   (   Rk  R   R  R;  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  y  s
    N(   R   R   R   R   R$  R#  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRn  m  s   		t   NetBIOSNameFieldc           B   s)   e  Z d  d d  Z d   Z d   Z RS(   i   i    c         C   s    t  i |  | | | d | d  S(   NRg  (   Rn  R   (   R   R  R  Ro  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sk   |  i  |  d } | d  j o
 d } n | d | 7} | |  } d i t d   |   } d | } | S(   Ni   R   RT   c         S   s0   t  d  t |   d ? t  d  t |   d @ S(   iA   i   i   (   R   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   Rk  R   RU   RN   (   R   R   R6   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    


c         C   sN   | i  d  i  d  } d i t d   | d  d  d  | d d  d    S(   NRh   RT   R   c         S   s.   t  t |   d  d @d >t |  d  d @ S(   i   i   i   (   R   R   (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    i   i   (   Rn   RU   RN   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R   R!  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRp    s   		t   StrLenFieldc           B   s#   e  Z d d d  d  Z d   Z RS(   i    c         C   sf   t  i |  | | d | | |  _ | d  j	 p | d j o& t |  i i  | | d  |  _ n d  S(   NRg  i    c         S   s   t  |  |  | S(    (   RD   (   R   R.  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   Rf  R   Rk  R   Re  R   R   (   R   R  R  R.  Rk  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
    	c         C   s-   |  i  |  } | | |  i | | |   f S(   N(   Rk  R   (   R   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    N(   R   R   R   R   R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRq    s   t   FieldListFieldc           B   sY   e  Z d  Z d	 d d	 d	 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(
   i   i    c         C   s   | d  j o
 g  } n t i |  | |  | |  _ | |  _ | |  _ | d  j	 p | d j o& t |  i i  | | d  |  _ n d  S(   Ni    c         S   s   t  |  |  | S(    (   RD   (   R   R.  Rg  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (	   R   R  R   Rl  Rk  t   fieldRe  R   R   (   R   R  R  Rs  R.  Rg  Rk  Rl  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    
			c         C   s%   t  |  t j o t |  Sn d S(   Ni   (   R   R   Rq   (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c            s   t     f d   | D  S(   Nc         3   s(   x! |  ] }   i  i  |  Vq Wd  S(   N(   Rs  R  (   RI   R
  (   R   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pys	   <genexpr>  s    (   R   (   R   R   RB   (    (   R   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   | d  j o
 g  } n | S(   N(   R   (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    
c         C   s&   t  |  t j	 o | g Sn | Sd  S(   N(   R   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s?   |  i  | |  } x& | D] } |  i i | | |  } q W| S(   N(   R!  Rs  R#  (   R   R   R   RB   R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#    s
     c         C   s   d  } } |  i d  j	 o |  i |  } n$ |  i d  j	 o |  i |  } n g  } d } | d  j	 o | |  | | } } n xa | oY | d  j	 o  | d j o Pn | d 8} n |  i i | |  \ } } | i |  q W| | | f S(   NR   i    i   (   R   Rk  Rl  Rs  R$  Rf   (   R   R   R   R   R   RB   R  R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s"    

N(   R   R   R+  R   R   R  R  R!  R  R#  R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRr    s   					t   FieldLenFieldc           B   s,   e  Z d d  d d   d d  Z d   Z RS(   R/   c         C   s   | S(    (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s_   t  i |  | | |  | |  _ | |  _ | |  _ | d  j	 o t |  i i  | |  _ n d  S(   N(	   R  R   t	   length_oft   count_oft   adjustR   Re  R   R   (   R   R  R  Ru  RE  Rv  Rw  R.  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    			c         C   s   | d  j o~ |  i d  j	 o. | i |  i  \ } } | i | |  } n+ | i |  i  \ } } | i | |  } |  i | |  } n | S(   N(   R   Ru  t   getfield_and_valR  Rv  R  Rw  (   R   R   R6   R.  t   fvalR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    N(   R   R   R   R   R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRt    s   s   DES-CBCs   IDEA-CBCs   Blowfish-CBCs   RC5-R16-B64-CBCs   3DES-CBCs   CAST-CBCi   s   AES-CBCs   CAMELLIA-CBCt
   Encryptiont   MD5t   SHAt   Tigers   SHA2-256s   SHA2-384s   SHA2-512t   Hasht   PSKt   DSSs   RSA Sigs   RSA Encryptions   RSA Encryption Reviseds   ElGamal Encryptions   ElGamal Encryption Reviseds	   ECDSA Sigi  t   HybridInitRSAi  t   HybridRespRSAi  t   HybridInitDSSi  t   HybridRespDSSi  t   XAUTHInitPreSharedi  t   XAUTHRespPreSharedi  t   XAUTHInitDSSi  t   XAUTHRespDSSi  t   XAUTHInitRSAi  t   XAUTHRespRSAi  t   XAUTHInitRSAEncryptioni  t   XAUTHRespRSAEncryptioni  t   XAUTHInitRSARevisedEncryptioni  t   XAUTHRespRSARevisedEncryptiot   Authenticationt	   768MODPgrt
   1024MODPgrt	   EC2Ngr155t	   EC2Ngr185t
   1536MODPgri   t
   2048MODPgri   t
   3072MODPgrt
   4096MODPgri   t
   6144MODPgri   t
   8192MODPgrt	   GroupDesct   MODPt   ECPt   EC2Nt	   GroupTypet
   GroupPrimet   GroupGenerator1t   GroupGenerator2i	   t   GroupCurveAi
   t   GroupCurveBi   t   Secondst	   Kilobytest   LifeTypei   t   LifeDurationi   t   PRFt	   KeyLengtht	   FieldSizet
   GroupOrdert   ISAKMPTransformSetFieldc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   i   c   	      C   s   | \ } } t  i | | h  d f  \ } } } | i | |  } d } | d
 @o` | p t d |  n d } x4 | o, t | d @ | } | d L} | d 7} qu W| } n | d O} t i d	 | |  | S(   Ni    R   i  s9   %r should not be TLV but is too big => using TLV encodingi   i   i   i   s   !HHi  (   t   ISAKMPTransformTypesR   R   R   R   R   (	   R   t   .1t   typRB   t   type_valt   enc_dictt   tlvR   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   type2num;  s   $



c         C   s<   t  i | | h  f  } | d i | |  } | d | f S(   Ni   i    (   t   ISAKMPTransformNumR   (   R   R  R  RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   num2typeK  s    c         C   s4   | d  j o d Sn t |  i |  } d i |  S(   NR   (   R   RN   R  RU   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  O  s    c      
   C   sT  g  } x"t  |  d j ot i d | d   \ } | d @} | o t i d | d d ! \ } | d t  |  j o t d |  n | d d | !} t d   t i d d t  |  f |  d	  } n- | d
 M} d	 } t i d | d d ! \ } | d | } | i |  i | |   q	 Wt  |  d	 j o t d |  n | S(   Ni   s   !Hi   i   s(   Bad length for ISAKMP tranform type=%#6xc         S   s   |  d  >| BS(   l    (    (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   f  s    s   !%sRj  i    i  s2   Extra bytes after ISAKMP transform dissection [%r](   Rq   R   R   R   t   reduceRf   R  (   R   R   R  R  t
   trans_typet   is_tlvt	   value_lenR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   T  s$    6
(   R   R   R+  R  R  R!  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  9  s
   			t   StrNullFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | |  i  | |  d S(   NRh   (   R!  (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#  r  s    c         C   sL   | i  d  } | d j  o d | f Sn | | d |  i | | |   f S(   NRh   i    R   i   (   Rm   R   (   R   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  t  s    c         C   s   t  t d d  d  S(   Ni    i  Rh   (   R<  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  z  s    (   R   R   R#  R$  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  q  s   		t   StrStopFieldc           B   s&   e  Z d  d  Z d   Z d   Z RS(   i    c         C   s)   t  i |  | |  | |  _ | |  _ d  S(   N(   R  R   t   stopt   additionnal(   R   R  R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   ~  s    	c         C   sY   | i  |  i  } | d j  o d | f Sn | t |  i  |  i 7} | | | |  f S(   Ni    R   (   Rm   R  Rq   R  (   R   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s
    c         C   s   t  t d d  |  i  S(   Ni    i  (   R<  R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   R   R$  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  }  s   	t   LenFieldc           B   s   e  Z d    Z RS(   c         C   s$   | d  j o t | i  } n | S(   N(   R   Rq   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    (   R   R   R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BCDFloatFieldc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  d |  S(   Ni   (   Rr   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    c         C   s   | d S(   Ng      p@(    (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R!  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	t   BitFieldc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s5   t  i |  | |  | d j  |  _ t |  |  _ d  S(   Ni    (   R  R   t   revt   absR:  (   R   R  R  R:  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sJ   |  i  d j o t i |  } n$ |  i  d j o t i |  } n | S(   Ni   i    (   R:  R4   t   ntohsR  (   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    c         C   s   |  i  | |  } t |  t j o | \ } } } n d } d } |  i o |  i |  } n | |  i K} | | d |  i >d @O} | |  i 7} xH | d j o: | d 8} | t i d | | ? } | d | >d M} q W| o | | | f Sn | Sd  S(   Ni    l    i   i   s   !B(   R!  R   Ro   R  R  R:  R   R   (   R   R   R   RB   t   bitsdoneR
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#    s"    

c   	      C   sS  t  |  t j o | \ } } n d } |  i | d d d } | |  } t i d | |  } d } x8 t |  D]* } | t | |  | | d d >O} qu W| d | d | >d M} | | d |  i | ?} |  i o |  i |  } n | |  i 7} | | d } | d } |  i	 | |  } | o | | f | f Sn | | f Sd  S(   Ni    i   i   s   !%dBl    l    (
   R   Ro   R:  R   R   R   R   R  R  R   (	   R   R   R   t   bnt   nb_bytesR   t   bytesR  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s*    
 (

c         C   s   t  d d |  i d  S(   Ni    i   i   (   R  R:  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   R   R  R#  R$  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
   				!t   BitFieldLenFieldc           B   s&   e  Z d d d    d  Z d   Z RS(   c         C   s   | S(    (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s5   t  i |  | | |  | |  _ | |  _ | |  _ d  S(   N(   R  R   Ru  Rv  Rw  (   R   R  R  R:  Ru  Rv  Rw  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    		c         C   s   t  i i |  | |  S(   N(   Rt  R!  t   im_func(   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    N(   R   R   R   R   R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t	   XBitFieldc           B   s   e  Z d    Z RS(   c         C   s   t  |  i | |   S(   N(   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    (   R   R   R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t	   EnumFieldc           B   s8   e  Z d  d  Z d   Z d   Z d   Z d   Z RS(   R/   c   	      C   s   h  } |  _  h  } |  _ t |  t j o t t |   } n | i   } t d   |  o | | } } n x* | D]" } | | | | <| | | | <qz Wt i	 |  | | |  d  S(   Nc         S   s   t  |   t j S(    (   R   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (
   t   i2st   s2iR   R   R  Rq   RQ   R"   R  R   (	   R   R  R  t   enumRE  R  R  RQ   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s     c         C   s(   t  |  t j o |  i | } n | S(   N(   R   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   any2i_one  s    c         C   sJ   |  t  i j o0 t | t  o | |  i j o |  i | Sn t |  S(   N(   R   t   noenumR`   R  R  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   i2repr_one  s    1c            sD   t  |  t j o t |   f d  |  Sn   i | |  Sd  S(   Nc            s     i  | |   S(    (   R  (   R   R   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   R   R   RN   R  (   R   R   R6   (    (   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c            sD   t  |  t j o t |   f d  |  Sn   i | |  Sd  S(   Nc            s     i  | |   S(    (   R  (   R   R   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    (   R   R   RN   R  (   R   R   R6   (    (   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    (   R   R   R   R  R  R  R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
   			t   CharEnumFieldc           B   s   e  Z d  d  Z d   Z RS(   t   1sc         C   sg   t  i |  | | | |  |  i i   } | o4 t | d  d j o |  i |  i |  _ |  _ n d  S(   Ni    i   (   R  R   R  RQ   Rq   R  (   R   R  R  R  RE  RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s(   t  |  d j o |  i | } n | S(   Ni   (   Rq   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   BitEnumFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s8   t  i |  | | |  | d j  |  _ t |  |  _ d  S(   Ni    (   R  R   R  R  R:  (   R   R  R  R:  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  i |  | |  S(   N(   R  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   t  i |  | |  S(   N(   R  R"  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"     s    (   R   R   R   R  R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   		t   ShortEnumFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | | d  d  S(   NR/   (   R  R   (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   $  s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s   t   LEShortEnumFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | | d  d  S(   Ns   <H(   R  R   (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   (  s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  '  s   t   ByteEnumFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | | d  d  S(   NRj  (   R  R   (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   ,  s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  +  s   t   IntEnumFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | | d  d  S(   NR  (   R  R   (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   0  s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  /  s   t   SignedIntEnumFieldc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  i |  | | | d  d  S(   NR   (   R  R   (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   4  s    c         C   s   t    S(   N(   R0  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  6  s    (   R   R   R   R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  3  s   	t   LEIntEnumFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | | d  d  S(   Ns   <I(   R  R   (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   :  s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  9  s   t   XShortEnumFieldc           B   s   e  Z d    Z RS(   c         C   sJ   |  t  i j o0 t | t  o | |  i j o |  i | Sn t |  S(   N(   R   R  R`   R  R  R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  >  s    1(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  =  s   t   LELongFieldc           B   s   e  Z d    Z RS(   c         C   s   t  i |  | | d  d  S(   Ns   <Q(   R  R   (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   E  s    (   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  D  s   t   LEFieldLenFieldc           B   s#   e  Z d d  d d   d d  Z RS(   s   <Hc         C   s   | S(    (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   J  s    c         C   s/   t  i |  | | d | d | d | d | d  S(   NRu  RE  R.  Rw  (   Rt  R   (   R   R  R  Ru  RE  Rv  Rw  R.  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   J  s    N(   R   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  I  s   t
   FlagsFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s[   t  i |  | | |  t |  t j |  _ |  i o t d   |  |  _ n
 | |  _ d  S(   Nc         S   s   |  g S(    (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   S  s    (   R  R   R   R   R  RN   t   names(   R   R  R  R:  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   O  s
    
c         C   s{   t  |  t j od |  i o t d   | i d   } n d } x( | D]  } | d |  i i |  >O} qI W| } n | S(   Nc         S   s   |  g S(    (    (   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   Y  s    t   +i    i   (   R   R   R  RN   Rp   R  RS  (   R   R   R6   RJ   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  V  s    
 
c         C   s   t  |  t j p t  |  t j o t |  Sn |  i o
 g  } n d } d } x@ | o8 | d @o | |  i | 7} n | d 7} | d L} qW W|  i o d i |  } n | S(   NR   i    i   R  (   R   R   Ro   R  R  R  RU   (   R   R   R6   Rg   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"  _  s    &




(   R   R   R   R  R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  N  s   			t   IPoptionsFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | d d t  |  d d S(   NRh   i   i   (   Rq   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  u  s    c         C   sK   | i  d d } | d j  o t d | i   d } n | | | |  f S(   Ni   i   i    s   bad ihl (%i). Assuming ihl=5(   t   ihlR   (   R   R   R   t   opsz(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  w  s
    
c         C   s   t  t d d   S(   Ni    i'   (   R;  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  }  s    (   R   R   R!  R$  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  t  s   		t   EOLt   NOPt   MSSs   !Ht   WScales   !Bt   SAckOKt   SAckR  Rs  s   !IIt	   AltChkSums   !BHt   AltChkSumOptt   TCPOptionsFieldc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   i   c         C   sW   | i  d d } | d j  o t d | i   d } n | | |  i | | |   f S(   Ni   i   i    s$   bad dataofs (%i). Assuming dataofs=5(   t   dataofsR   R   (   R   R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s
    
c   	      C   s  g  } x| ot  | d  } | d j o | i d
  | d } Pn | d j o | i d  | d } q	 n t  | d  } | d j  o t d |  d } n | d | !} t d i |  o t d | \ } } | d j o | d t |  d	 7} n | oS t i |  t |  j o7 t i	 | |  } t |  d j o | d } qan | i | | f  n | i | | f  | | } q	 W| S(   Ni    R  i   R  i   s-   Malformed TCP option (announced length is %i)i   s   %iIi   (   R  N(   R  N(
   R   Rf   R   R   t
   TCPOptionsR  Rq   R   R  R   (	   R   R   R6   t   optt   onumt   olent   ovalt   onamet   ofmt(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s8    



#c         C   s  d } x| D]\ } } t  |  t j o| d j o | d 7} q qk| d j o | d 7} q qkt d i |  o t d | } t d | d } | d j o | d	 t |  7} n | d  j	 oV t  |  t j	 p d
 | j o6 t  |  t j	 o | f } n t i | |  } q9qkt	 d |  q n/ | } t  |  t j	 o t	 d |  q n | t
 |  t
 d t |   | 7} q W| d d t |  d d S(   NR   R  s   R  Rh   i   i    i   s   %iIR   s   option [%s] unknown. Skipped.s   option [%i] is not string.i   i   i   (   R   R   R  R  Rq   R   Ro   R   R   R   R   (   R   R   R6   R  R  R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s6     

-,c         C   s   g  S(   N(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   R+  R$  R   R!  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
   			t   DNSStrFieldc           B   s   e  Z d    Z d   Z RS(   c         C   sr   g  } | i  d  D] } | | d  q ~ } t d   |  } d i |  } | d d j o | d 7} n | S(   NR   i?   c         S   s   t  t |    |  S(    (   R   Rq   (   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R   iRh   (   Rp   RN   RU   (   R   R   R6   R  RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    .c         C   ss   d } x` t  | d  } | d } | p Pn | d @o t d   q	 | | |  d 7} | | } q	 | | f S(   NR   i    i   i   s.   DNS message can't be compressed at this point!R   (   R   R   (   R   R   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    
(   R   R   R!  R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	t   DNSRRCountFieldc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   i   c         C   s    t  i |  | |  | |  _ d  S(   N(   RW  R   t   rr(   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sW   t  | |  i  } d } x8 t | t  p t | t  o | i } | d 7} q W| S(   Ni    i   (   RD   R  R`   t   DNSRRt   DNSQRR  (   R   R   R6   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _countRR  s    #	c         C   s$   | d  j o |  i |  } n | S(   N(   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    c         C   s$   | d  j o |  i |  } n | S(   N(   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R,  R   R  R!  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
   			c         C   sP  d } d } | g } x| t  |   j o t d | t  |   f  Pn t |  |  } | d 7} | d @o | p | d } n | t  |   j o t d |  Pn | d @d >t |  |  d	 } | | j o t d
  Pn | i |  q n8 | d j o* | |  | | | !d 7} | | 7} q n Pq | o
 | } n | | f S(   NR   i    s&   DNS RR prematured end (ofs=%i, len=%i)i   i   s%   DNS incomplete jump token at (ofs=%i)i?   i   i   s   DNS decompression loop detectedR   (   Rq   R   R   Rf   (   R   Rc   R  R  t   jpathR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   DNSgetstr  s:    	
 


t
   DNSRRFieldc           B   s5   e  Z d  Z d  d  Z d   Z d   Z d   Z RS(   i   c         C   s)   t  i |  | d   | |  _ | |  _ d  S(   N(   Rf  R   R   t   countfldt   passon(   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   /  s    	c         C   s   | d  j o d Sn t |  S(   NR   (   R   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  3  s    c   
      C   s   | | | d !} t  i d |  \ } } } } | d 7} t d | | | | | ! }	 |	 i d	 j o t | |  d |	 _ n |	 ` | | 7} | |	 _ |	 | f S(
   Ni
   s   !HHIHRh   i   i   i   i   i    (   i   i   i   i   (   R   R   R  R   R  t   rdatat   rdlent   rrname(
   R   R  R   Rc   R  R   R  RQ  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   decodeRR7  s    

	c         C   s  t  |  t j o | \ } } n d } d  } t | |  i  } | t |  j o% t d |  i | f  | d f Sn xj | ob | d 8} t | |  \ } } |  i | | |  \ } } | d  j o
 | } q| | i	 |  q| W|  i
 o | | f | f Sn | | | f Sd  S(   Ni    s   wrong value: DNS.%s=%iR   i   (   R   Ro   R   RD   R  Rq   R   R  R  t   add_payloadR  (   R   R   R   Rc   R  R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  D  s$    



(   R   R   R,  R   R!  R  R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  -  s
   		t
   DNSQRFieldc           B   s   e  Z d  Z d   Z RS(   i   c         C   s>   | | | d !} | d 7} t  d |  } | | _ | | f S(   Ni   Rh   (   R  t   qname(   R   R  R   Rc   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ^  s
    
	(   R   R   R,  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  \  s   t
   RDataFieldc           B   s   e  Z d    Z d   Z RS(   c         C   s   d  } | i d j o t i } nE | i d j o t i } n( | i d j o t | d  d } n | d  j	 o t | |  } n | S(   Ni   i   i   i    (   R   R   R4   RZ  t   AF_INET6R  t	   inet_ntop(   R   R   R   t   family(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   h  s    c         C   s   | i  d j o | o t |  } q n | i  d j o! | o t t i |  } q nX | i  d j oG d i t d   | i d	    } t | d
  o | d 7} q n | S(   Ni   i   i   i   i   i   R   c         S   s   t  t |    |  S(    (   R   Rq   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   {  s    R   iRh   (   i   i   i   i   (	   R   R5   t	   inet_ptonR4   R  RU   RN   Rp   R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!  s  s    $(   R   R   R   R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  g  s   	t
   RDLenFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  i |  | d  d  d  S(   NR/   (   R  R   R   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s?   | d  j o. | i d  } t | i | | i   } n | S(   NR   (   R   t	   get_fieldRq   R!  R   (   R   R   R6   t   rdataf(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    c         C   s?   | d  j o. | i d  } t | i | | i   } n | S(   NR   (   R   R  Rq   R!  R   (   R   R   R6   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R   R!  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   		I~    t   TimeStampFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s#   t  i |  | | |  | |  _ d  S(   N(   R  R   R:  (   R   R  R  R:  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   su   t  i |  | |  \ } } | oC | d L} | t 8} d d k l } l } | d | |   } n d } | | f S(   Ni    i(   Rc  Rb  s   %a, %d %b %Y %H:%M:%S +0000R   (   R  R$  t   ntp_basetimeR   Rc  Rb  (   R   R   R   t	   timestampRc  Rb  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    

c         C   s   d } t  |  t j o: d d k l } l } t | | |    t d } n; | d j o' d d k l } t |    t } n | } | d K} t i |  | | |  S(   Ni(   t   strptimet   mktimei  (   R   i    (	   R   R   R   R  R  Rr   R  R  R#  (   R   R   R   RB   RT  R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#    s    $
(   R   R   R   R$  R#  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   		t   ICMPTimeStampFieldc           B   s)   e  Z e i d   Z d   Z d   Z RS(   sM   ([0-2]?[0-9])[Hh:](([0-5]?[0-9])([Mm:]([0-5]?[0-9])([sS:.]([0-9]{0,3}))?)?)?$c         C   sr   | d  j o d SnZ t | d  \ } } t | d  \ } } t | d  \ } } d | | | t |  f Sd  S(   Ns   --i  i<   s   %d:%d:%d.%d(   R   t   divmodRr   (   R   R   RB   t   sect   milliR   t   hour(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    c   	      C   s   t  |  t j o |  i i |  } | o | i   \ } } } } } } } } t | p d d d   } t |  d t | p d  d t | p d  d | } q d } n, | d  j o t t i   d	 d  } n | S(
   NR   t   000i   i<   i    i  i   i  iQ (   R   R   t   re_hmsmRL  R  Rr   R   R   (	   R   R   RB   t   hmsmsR  RL   R  R   t   ms(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    %B
(   R   R   Rj   Rk   R  R"  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	t
   FloatFieldc           B   s   e  Z d    Z RS(   c         C   sU   t  i |  | |  \ } } | d ?} | d d >d @} | d :} | | } | | f S(   Ni   l    i    i   g      @i!   (   R  R$  (   R   R   R   R  R  t   frac(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    


(   R   R   R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   Dot11SCFieldc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | i  d j S(   Ni   (   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRI    s    c         C   s2   |  i  |  o t i |  | | |  Sn | Sd  S(   N(   RI  RX  R#  (   R   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#    s    c         C   s5   |  i  |  o t i |  | |  Sn | d  f Sd  S(   N(   RI  RX  R$  R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    (   R   R   RI  R#  R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   		t   ASN1F_badsequencec           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   t   ASN1F_elementc           B   s   e  Z RS(    (   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s   t   ASN1F_optionnalc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   _field(   R   Rs  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   t  |  i |  S(   N(   RD   R#  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sq   y |  i  i | |  SWnS t j
 o |  i  i | d   | Sn+ t j
 o |  i  i | d   | Sn Xd  S(   N(   R#  t   dissectR   t   set_valR   R  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    c         C   s+   |  i  i |  o d Sn |  i  i |  S(   NR   (   R#  t   is_emptyt   build(   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'    s    (   R   R   R   R   R$  R'  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s   				t   ASN1F_fieldc           B   s   e  Z d  Z d  Z e i Z e Z d 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(   i    c         C   s0   | d  j	 o | |  _ n | |  _ | |  _ d  S(   N(   R   Ry  R  R  (   R   R  R  Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    	c         C   s!   | d  j o
 d } n t |  S(   Ni    (   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    
c         C   s   | S(   N(    (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   | S(   N(    (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s%   |  i  i | i  i | d |  i S(   NRy  (   t   ASN1_tagR  t
   ASN1_codecR{  Ry  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   | d  j o
 d } n t | t  o |  i t i j p9 | i t i j p& | i t i j p |  i | i j o | i	 | i
  Sq t d | |  i |  i f   n |  i i | i
  i	 |  S(   Ni    s6   Encoding Error: got %r instead of an %r for field [%s](   R   R`   R  R)  RN  R  R  R  R  R  R*  Rq  R  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    
#c         C   s   t  | d  o | i   Sn t |  t j oT | } xJ t t |   D]2 } t | | t  o | | i   | | <qK qK Wn | S(   NR  (   RM  R  R   R   R  Rq   R`   R(  (   R   R6   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%  $  s      c         C   s   |  i  | t | |  i   S(   N(   R!  RD   R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'  .  s    c         C   s   t  | |  i |  d  S(   N(   RG   R  (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%  1  s    c         C   s   t  | |  i  d  j S(   N(   RD   R  R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR&  3  s    c         C   s,   |  i  | |  \ } } |  i | |  | S(   N(   R   R%  (   R   R   R   R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  6  s    c         C   s   |  g S(   N(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_fields_list;  s    c         C   s   t  |  i  S(   N(   R/  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR0  >  s    c         C   s   |  i  S(   N(   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   @  s    c         C   s   |  i  | j S(   N(   R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   B  s    c         C   s   |  i  S(   N(   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV   D  s    c         C   s   t    S(   N(   R/  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  F  s    N(   R   R   R,  R+  RN  R  R)  Ry  R   R   R"  R  R  R   R!  R%  R'  R%  R&  R$  R+  R0  R   R   RV   R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR(     s*   							
									t   ASN1F_INTEGERc           B   s   e  Z e i Z d    Z RS(   c         C   s   t  d d  S(   Ni   i@   i   l            l         l            l    (   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  L  s    (   R   R   RN  R  R)  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR,  J  s   	t
   ASN1F_NULLc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR-  O  s   t   ASN1F_enum_INTEGERc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   t  i |  | |  h  } |  _ h  } |  _ t |  t j o t t |   } n | i   } t	 d   |  o | | } } n x* | D]" } | | | | <| | | | <q Wd  S(   Nc         S   s   t  |   t j S(    (   R   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   [  s    (
   R,  R   R  R  R   R   R  Rq   RQ   R"   (   R   R  R  R  R  R  RQ   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   S  s     c         C   s(   t  |  t j o |  i | } n | S(   N(   R   R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  `  s    c         C   s   |  i  i | t |   S(   N(   R  R   R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  d  s    c            sD   t  |  t j o t |   f d  |  Sn   i | |  Sd  S(   Nc            s     i  | |   S(    (   R  (   R   R   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   i  s    (   R   R   RN   R  (   R   R   R6   (    (   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  g  s    c            sD   t  |  t j o t |   f d  |  Sn   i | |  Sd  S(   Nc            s     i  | |   S(    (   R  (   R   R   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   n  s    (   R   R   RN   R  (   R   R   R6   (    (   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"  l  s    (   R   R   R   R  R  R  R"  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR.  R  s
   				t   ASN1F_STRINGc           B   s   e  Z e i Z d    Z RS(   c         C   s   t  t d d   S(   Ni    i  (   R7  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  t  s    (   R   R   RN  R  R)  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR/  r  s   	t   ASN1F_PRINTABLE_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR0  w  s   t   ASN1F_BIT_STRINGc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR1  z  s   t   ASN1F_UTC_TIMEc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR2  }  s   t	   ASN1F_OIDc           B   s   e  Z e i Z d    Z RS(   c         C   s   t    S(   N(   RC  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   RN  R  R)  R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR3    s   	t   ASN1F_SEQUENCEc           B   sP   e  Z e i Z d    Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(   c         O   s+   d | j o | d |  _  n | |  _ d  S(   NR)  (   R)  R  (   R   R  RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   d |  i  i |  i f S(   Ns   <%s%r>(   R   R   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    c         C   s(   x! |  i  D] } | i | |  q
 Wd  S(   N(   R  R%  (   R   R   RB   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%    s    
 c         C   s0   x) |  i  D] } | i |  p t Sq
 q
 Wt S(   N(   R  R&  RZ   R[   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR&    s
    
 c         C   s   t  d   |  i g   S(   Nc         S   s   |  | i    S(    (   R+  (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    (   R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR+    s    c            s.   t    f d   |  i d  } |  i   |  S(   Nc            s   |  | i     S(    (   R'  (   R6   RJ   (   R   (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R   (   R  R  R!  (   R   R   R   (    (   R   sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'    s    c         C   s   |  i  i | i  } y_ | i |  \ } } } x# |  i D] } | i | |  } q: W| o t d |  n | SWn! t j
 o } t |   n Xd  S(   Ns'   Too many bytes to decode sequence: [%r](	   R)  R  R*  R  R  R$  R   Rq  R   (   R   R   R   R  R   R  R*  R|   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    
 (   R   R   RN  R  R)  R   RV   R%  R&  R+  R'  R$  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR4    s   							t	   ASN1F_SETc           B   s   e  Z e i Z RS(    (   R   R   RN  R  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR5    s   t   ASN1F_SEQUENCE_OFc           B   sq   e  Z d  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z d	   Z
 d
   Z d   Z RS(   i   i0   c         C   s.   | |  _  t |  |  _ | |  _ | |  _ d  S(   N(   t   asn1pktR   R  R  R  (   R   R  R  R7  R)  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    		c         C   s   | d  j o g  Sn | S(   N(   R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s    c         C   s   |  g S(   N(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR+    s    c         C   s   t  i |  | |  d  S(   N(   R(  R%  (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%    s    c         C   s   t  i |  |  S(   N(   R(  R&  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR&    s    c         C   s~   t  | |  i  } t | t  o | i t i j o
 | } n0 | d  j o
 d } n d i t	 t
 |   } |  i | |  S(   NR   (   RD   R  R`   R  R  RN  R  R   RU   RN   R   R!  (   R   R   RB   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'    s    #

c         C   s   t  i |  | |  d  S(   N(   R(  R%  (   R   R   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%    s    c   
      C   s   |  i  i | i  } | i |  \ } } } g  } x | o| y |  i |  } Wn) t j
 o }	 | i t |   Pn X| i |  t | j o | t i } | t i	 `
 q6 Pq6 W|  i | |  | S(   N(   R)  R  R*  R  R7  R   Rf   RV  R!  Ri  R  R%  (
   R   R   R   R  R   t   s1R  R  Rc   R|   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s     
c         C   s   t  |  i    S(   N(   t   fuzzR7  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    c         C   s   d |  i  i |  i f S(   Ns   <%s %s>(   R   R   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    (   R   R   R,  R+  R   R"  R+  R%  R&  R'  R$  R\  RV   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR6    s   									t   ASN1F_PACKETc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   i   c         C   s    t  i |  | |  | |  _ d  S(   N(   t
   ASN1_fieldR   R  (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s!   | d  j o
 d } n t |  S(   NR   (   R   R   (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s    
c         C   so   y | |  } Wn t  j
 o t |  } n X| t } d } | d  j	 o | i } | i ` n | | f S(   NR   (   R   RV  RY  R   R!  Ri  R  (   R   R  R6   R   t   cpad(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   extract_packet  s    
	c         C   s   |  i  |  i |  S(   N(   R=  R  (   R   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R,  R   R!  R=  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR:    s
   			t   ASN1F_CHOICEc           B   s,   e  Z e i Z d    Z d   Z d   Z RS(   c         G   sC   | |  _  h  |  _ x! | D] } | |  i | i i <q W| |  _ d  S(   N(   R  R6  t	   ASN1_rootR)  R  (   R   R  R  R\   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    		 c         C   s   t  |  d j o t   d f St d   n t | d  |  i j o= t |  d f St d t | d  |  i i   f   n t i |  |  i t | d  |  } | S(   Ni    R   s   ASN1F_CHOICE: got empty strings+   Decoding Error: choice [%i] not found in %r(   Rq   RV  Rq  R   R6  RQ   R:  R=  (   R   R   R6   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    -&c         C   s   t  t d   |  i i      S(   Nc         S   s   t  |     S(    (   R9  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   	  s    (   R3  RN   R6  RO  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\    s    (   R   R   RN  R  R)  R   R   R\  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR>    s   			
t   Packet_metaclassc           B   s   e  Z d    Z d   Z RS(   c         C   sF   t  t |   i |  | | |  } x | i D] } | i |  q+ W| S(   N(   R  R@  R  Rc  R  (   R  R  R  Ry   t   newclsR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    !
 c         C   s<   x) |  i  D] } | i | j o | Sq
 q
 Wt |   d  S(   N(   Rc  R  R  (   R   RE   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
    
 (   R   R   R  R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR@    s   	t   NewDefaultValuesc           B   s   e  Z d  Z d   Z RS(   s  NewDefaultValues metaclass. Example usage:
    class MyPacket(Packet):
        fields_desc = [ StrField("my_field", "my default value"),  ]
        
    class MyPacket_variant(MyPacket):
        __metaclass__ = NewDefaultValues
        my_field = "my new default value"
    c      	   C   s   d  } x, | D]$ } t | d  o | i } Pq q W| d  j o t d   n g  } xU | D]M } | i | j o* | i   } | | i | _ | | i =n | i |  q_ W| | d <t t	 |   i
 |  | | |  S(   NRc  s   No fields_desc in superclasses(   R   RM  Rc  R   R  R  R  Rf   R  RB  R  (   R  R  R  Ry   t   fieldsR  t
   new_fieldsR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  &  s$     		 
(   R   R   RW  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRB    s   R(  c           B   s  e  Z e Z dJ Z g  Z g  Z h  Z dJ Z	 g  Z
 d  Z d Z d  Z e d    Z e d    Z e d    Z d dJ d  dJ 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$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d    Z, d!   Z- d"   Z. d  d#  Z/ d$   Z0 d%   Z1 d  d&  Z2 dJ d'  Z3 dJ d(  Z4 d  d d)  Z5 d*   Z6 d+   Z7 d,   Z8 d-   Z9 d.   Z: d/   Z; d0   Z< d1   Z= d2   Z> dJ d3  Z? d4   Z@ d5   ZA d6   ZB d7   ZC d8   ZD d9   ZE d:   ZF d;   ZG d dJ d<  ZH d=   ZI d>   ZJ d?   ZK d@ d d dA  ZL dB   ZM d dC  ZN dD   ZO d  dE  ZP dJ dF  ZQ dG   ZR dH   ZS dI   ZT RS(K   i    i   c         C   s   |  t     S(   N(   t   import_hexcap(   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   from_hexcapI  s    c         C   sI   xB |  i  D]7 \ } } d | i d i d   | i   D  f GHq
 Wd  S(   Ns	   %-20s  %ss   , c         s   s!   x |  ] } d  d | Vq Wd S(   s   %-12ss   %s=%rN(    (   RI   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pys	   <genexpr>P  s    (   t   payload_guessR   RU   R  (   R   Ry  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   upper_bondsM  s    
 c         C   sO   xH |  i  i   D]7 \ } } d | i d i d   | i   D  f GHq Wd  S(   Ns	   %-20s  %ss   , c         s   s!   x |  ] } d  d | Vq Wd S(   s   %-12ss   %s=%rN(    (   RI   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pys	   <genexpr>U  s    (   t   overload_fieldsR  R   RU   (   R   t   lowerRy  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   lower_bondsR  s     R   c         K   sa  t  i    |  _  d |  _ |  i d  j o |  i i |  _ n |  i g |  i |  _ h  |  _ h  |  _ h  |  _	 h  |  _
 g  |  _ t   |  i d <|  i   | |  _ d |  _ | o) |  i |  | p |  i |   q n x: | i   D], } |  i |  i |  | |  |  i	 | <q Wt |  t j o | |  _ n' | d  j o g  |  _ n | g |  _ d  S(   Ni    R  i   (   R   t	   sent_timeR  R   R   R   t
   aliastypest   default_fieldst   overloaded_fieldsRC  t	   fieldtypet   packetfieldst	   NoPayloadR?   t   init_fieldsRi  t   initializedR$  t   dissection_doneRQ   R  R  R   R   t   post_transforms(   R   t   _pktt   post_transformt	   _internalt   _underlayerRC  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   W  s4    						
		 *c         C   s   |  i  |  i  d  S(   N(   t   do_init_fieldsRc  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRS  s  s    c         C   sV   xO | D]G } | i  |  i | i <| |  i | i <| i o |  i i |  q q Wd  S(   N(   R  RN  R  RP  R,  RQ  Rf   (   R   t   flistR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR[  v  s     
c         C   s!   |  i  |  |  i i |  d S(   s3   DEV: will be called after a dissection is completedN(   t   post_dissectionR  RU  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRU  }  s    c         C   s   d S(   s7   DEV: is called after the dissection of the whole packetN(    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR]    s    c         C   s   |  i  | S(   s:   DEV: returns the field instance from the name of the field(   RP  (   R   R.  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   | d  j o d  Sn t |  i t  p |  i i |  n t | t  oZ | |  i d <| i |   x |  i D]. } | i	 i
 |  o | i	 | |  _ Pqp qp WnD t |  t j o t d |  |  i d <n t d t |    d  S(   NR  R!  s2   payload must be either 'Packet' or 'str', not [%s](   R   R`   R  RR  R  R(  R?   t   add_underlayerRM  RI  R  RO  R   R   RV  R4  R  (   R   R  RT  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
 c         C   s-   |  i  i |   t   |  i d <h  |  _ d  S(   NR  (   R  t   remove_underlayerRR  R?   RO  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   remove_payload  s    c         C   s   | |  _  d  S(   N(   Ri  (   R   Ri  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR^    s    c         C   s   d  |  _ d  S(   N(   R   Ri  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR_    s    c         C   s   |  i    } |  i i   | _ x7 | i D], } |  i |  i | i |  | i | <q( W|  i i   | _ |  i i   | _ |  i i   | _ |  i | _ |  i	 | _	 |  i
 | _
 |  i i   | i d <| i i |  | S(   s$   Returns a deep copy of the instance.R  (   R   RC  R  R  R%  RN  RO  RI  Ri  t   explicitRV  R  R?   R^  (   R   R  RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
 *c         C   sm   | |  i  j o |  i  | Sn | |  i j o |  i | Sn | |  i j o |  i | Sn |  i i |  S(   N(   RC  RO  RN  R  t   getfieldval(   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRb    s    c         C   s   | |  i  j o |  i |  |  i  | f Sn | |  i j o |  i |  |  i | f Sn | |  i j o |  i |  |  i | f Sn |  i i |  S(   N(   RC  R  RO  RN  R  Rx  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRx    s    c         C   sX   |  i  o> |  i |  \ } } | d  j	 o | i |  |  Sn | Sn t |   d  S(   N(   RT  Rx  R   R  R  (   R   RE   R.  R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    
c         C   s   |  i  i |  oU |  i |  } | d  j o d   } n
 | i } | |  |  |  i | <d |  _ n< | d j o |  i   |  i |  n |  i	 i
 | |  d  S(   Nc         S   s   | S(    (    (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    i    R  (   RN  R  R  R   R  RC  Ra  R`  R  R  t   setfieldval(   R   RE   RB   R.  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRc    s    	
c         C   sM   |  i  o2 y |  i | |  Wn t j
 o q< Xd  Sn | |  i | <d  S(   N(   RT  Rc  R  R?   (   R   RE   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __setattr__  s    
c         C   sp   |  i  i |  o |  i  | =d |  _ nC |  i i |  o n, | d j o |  i   n |  i i |  d  S(   Ni    R  (   RC  R  Ra  RN  R`  R  t   delfieldval(   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRe    s    
c         C   sj   |  i  o/ y |  i |  Wn t j
 o q9 Xd  Sn |  i i |  o |  i | =n t |   d  S(   N(   RT  Re  R  R?   R  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __delattr__  s    
c      
   C   sh  d } t  i } x	|  i D] } t | t  o | i |   o q n | i |  i j o  | i |  |  i | i  } n7 | i |  i	 j o  | i |  |  i	 | i  } n q t | t
  o | i } | i } n | i } | i } | d | | i  | i d  | |  f 7} q Wd | i d  | i |  i i  | | i d  t |  i  | i d  f S(   NR   s    %s%s%st   =s   %s%s %s %s%s%sR   R   R   (   R   R   Rc  R`   R6  R8  R  RC  R"  RO  R-  t   emph_field_namet   emph_field_valuet
   field_namet   field_valueR>  t
   layer_nameR   R   R  R  (   R   R   R  R   RB   t   ncolt   vcol(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s2    	
 !  			c         C   s
   |  i    S(   N(   R'  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   sv   t  | t  o- |  i   } | i   } | i |  | Sn6 t |  t j o |  t d |  Sn | i |   Sd  S(   NR!  (   R`   R(  R  R  R   R   RV  t   __rdiv__(   R   R   t   cloneAt   cloneB(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __div__  s    c         C   s2   t  |  t j o t d |  |  Sn t  d  S(   NR!  (   R   R   RV  R4  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRo  '  s    c         C   s,   t  |  t j o |  g | Sn t  d  S(   N(   R   Rr   R4  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __mul__,  s    c         C   s   |  i  |  S(   N(   Rs  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __rmul__1  s    c         C   s   t  S(   N(   R[   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __nonzero__4  s    c         C   s   t  |  i    S(   N(   Rq   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __len__6  s    c         C   s?   d } x2 |  i  D]' } | i |  | |  i | i   } q W| S(   NR   (   Rc  R#  Rb  R  (   R   Rc   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   do_build8  s
    
 %c         C   s   | | S(   s3   DEV: called right after the current layer is build.(    (   R   R   t   pay(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   post_build>  s    c         C   s   |  i  i d d  S(   Nt   internali   (   R  R'  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   build_payloadB  s    c         C   s   |  i  p |  i   i   }  n |  i   } x |  i D] } | |  } q6 W|  i   } y |  i | |  } Wn3 t j
 o' t i	 d  |  i | |  } n X| p@ |  i
 i t  } | o | | i   7} n |  i |  } n | S(   Nsj   API changed! post_build() now takes 2 arguments. Compatibility is only assured for a short transition time(   Ra  RP   R   Rw  RV  R{  Ry  R4  R   R   R  RW  RY  R'  t
   build_done(   R   Rz  R   RT  Rx  Rc   RV  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'  E  s$    

 c         C   s   |  i  i |  S(   N(   R  R|  (   R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR|  X  s    c         C   s   d } g  } d } x |  i  D] } | i |  | |  i | i   } t |  t j o | t |  } | } n d } | i | | i |  |  i | i   | f  q W|  i	 i
 d d  \ } } | | 7} | i |  | f  | | f S(   NR   Rz  i   (   Rc  R#  Rb  R  R   R   Rq   Rf   R"  R  t   build_ps(   R   Rc   t   plR  R   Rg   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   do_build_ps[  s    
 !
2
c         C   s   |  i    \ } } | | f S(   N(   R  (   R   Rz  Rc   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR}  n  s    c         K   sk   |  i  |   } | d j o> d t i   } | i |  t i d t i i | f  n | i |  d S(   s   psdump(filename=None, layer_shift=0, rebuild=1)
Creates an EPS file describing a packet. If filename is not provided a temporary file is created and gs is called.s   /tmp/scapy.%is   %s '%s.eps' &N(	   R{  R   R   R  t   writeEPSfileRN  R   R   R  (   R   Rw   RA   t   canvasR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  z  s    !c         K   sk   |  i  |   } | d j o> d t i   } | i |  t i d t i i | f  n | i |  d S(   s   pdfdump(filename=None, layer_shift=0, rebuild=1)
        Creates a PDF file describing a packet. If filename is not provided a temporary file is created and xpdf is called.s   /tmp/scapy.%is   %s '%s.pdf' &N(	   R{  R   R   R  R  RN  R   R   R  (   R   Rw   RA   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    !c   %         s6  t  i i   } | o% |  i t |    i   \ } } n |  i   \ } } t |  } x$ | D] \ } } | t |  7} q` Wt |  } |  d }	 d  d }
 d } d } d  d  t d d d	 d
 t  i i	 } t d d d d
 t  i i	 } d           f d    d   } d    d d d  d  d   f d  } d \ } } x| o| i   } | i   \ } } |
 d 7}
 t  i i |	 | |
  d | i t  i i i g  } |
 d 7}
 | i   } | i t  i i d  | i | i   t  i i	 i t  i i | g  g  | i |  x| D]\ } } } | i   } t  i i |	 | |
  d t | i   } | d  j	 o) t |  d j o | d  d } qn d } t  i i |	 d | |
  d t |   } |
 d	 7}
 | o
| | | | | |  \ } } } } | i   }  | }  | i   }! | |!  }" | |   }# |  i t  i i  yW | d j  o% t  i i |" |# d d d d }$ n" t  i i |" |# d d d d }$ Wn n, X| i |$ t  i i i  t  i i! i" | g  | i |  n | i |  | i |  q8W| | 7} q^W| S(   Ni   i
   g        i    g?g?g333333?g?g      ?R   g?g      ?c         S   s;   g  } x% |  D] } | i  d t |   q Wd i |  S(   Ns   %02xRT   (   Rf   R   RU   (   R6   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
     c            s?   t  i i  |     |  d  |  t  i i i g  S(   Ns   \tt{%s}(   Ry  R  R:  t   Large(   R6   RJ   R  (   t   XMULt   YDUMPt   YMULR   t   XDSTART(    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   make_dump_txt  s    c         S   s7   t  i i |  i   |  i   |  i   |  i   d d S(   Nt	   relcenterg      ?(   g      ?g      ?(   Ry  R  t   rectR   t   bottomt   widtht   height(   Rb   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   make_box  s    c         S   s9  t  |   d j o1 |  d i   } | i t i i  | i   Sn|  d i   } | i t i i  |  d i   } | i t i i  t  |   d j o| i   | i   j ot i i t i i	 | i   | i
    t i i | i   | i
    t i i | i   | i    t i i | i   | i    t i i	 | i   | i
    t i i | i   | i
    t i i | i   | i    t i i | i   | i     Sn|  d i   } | | j o | i t i i  n |  d i   } | | j o$ | | j o | i t i i  n t i i t i i	 | i   | i
    t i i | i   | i
    t i i | i   | i    t i i | i   | i    t i i | i   | i    t i i | i   | i    t i i | i   | i
    t i i | i   | i
    t i i   	 Sd  S(   Ni   i    ii   i(   Rq   R|  t   enlargeRy  R  t   u_ptRa   R   R   t   movetoR  t   linetoR  t	   closepath(   R  R  t   fbt   lbt   gbR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   make_frame  s@    ,'&'i   c   
         s@  t  i i   } g  } xy |  oq |  | |  |  | | } }    | | |  }	 | i |	  | t |  7} | d j o d } | d 7} q q W| d  j o t  i i i } n | d  j o t  i i i } n | i	  |  | t  i
 i | g  t  i i i g  x | D] }	 | i |	  qW| | d i   | | f S(   Ni   i    i   i(   Ry  R  Rf   Rq   R   R  t   rgbt   redt   whitet   stroket   decot   filledt   stylet	   linewidtht   ThickR:  R|  (
   R   Rg  RJ   R   t   bkcolt   largR   t   tlistt   dmpR  (   R  R  (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   make_dump  s&    
7 s"   \font\cmssfont=cmss10\cmssfont{%s}i   i   s   [...]R   i   t	   absangle1t	   absangle2iiZ   (   i    g        (#   Ry  R  R   R   R}  Rq   Rg  R   R  R  R   R   t   popR  R  R:  R  R|  R  R  R  R  Ra   t   blackR  R  R:  R   t	   connectort   curveR  R  t   thint   earrowt   small(%   R   t   layer_shiftt   rebuildR  Rc   RT  t   YTXTR   R   t   XSTARTRJ   R   R   t	   backcolort	   forecolorR  R  t
   last_shiftt   last_yR  R  RC  t   ptt   ptbbR  Ry  t   fdumpR   t   ftt   vtt   dtR   t   dtbt   vtbt   bxvtt   bxdtt   cnx(    (   R   R  R  R  R  R  R  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR{    s    % 			&!

6
4 -.
$%%+c         C   s
   | d f S(   sl   DEV: to be overloaded to extract current layer's padding. Return a couple of strings (actual layer, padding)N(   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   extract_padding$  s    c         C   s   | S(   s?   DEV: is called right after the current layer has been dissected(    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   post_dissect(  s    c         C   s   | S(   s:   DEV: is called right before the current layer is dissected(    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   pre_dissect,  s    c         C   sb   |  i  } | i   xG | o? | o8 | i   } | i |  |  \ } } | |  i | i <q W| S(   N(   Rc  R  R  R$  RC  R  (   R   R   R\  R   Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   do_dissect0  s    

c      	   C   s   | o |  i  |  } y | | d d d |  } Wn t j
 o
   n t i os t | t  o( t | t  o t i	 d | i
  n$ t i	 d |  i i t |  f  | d  j	 o   q n t | d d d |  } n X|  i |  n d  S(   NRY  i   RZ  s   %s dissector faileds&   %s.guess_payload_class() returned [%s](   t   guess_payload_classt   KeyboardInterruptR   t   debug_dissectorR`   R   RQ  R(  R   R   R  R   R   R  R   RV  R  (   R   R   R  Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   do_dissect_payload:  s    
 #c         C   s{   |  i  |  } |  i |  } |  i |  } |  i |  \ } } |  i |  | o! t i o |  i t |   n d  S(   N(	   R  R  R  R  R  R   RZ  R  RY  (   R   R   t   paylRV  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$  L  s    c         C   s   x |  i  D] } xy | i D]n \ } } d } xJ | i   D]< } t |  |  p | | |  i |  j o d } Pq9 q9 W| o | Sq q Wq
 W|  i |  S(   se   DEV: Guesses the next payload class from layer bonds. Can be overloaded to use a different mechanism.i   i    (   RM  RG  RQ   RM  Rb  t   default_payload_class(   R   R  RT  Ry  R  R  RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  Y  s    
 
  +	c         C   s   t  S(   se   DEV: Returns the default payload class if nothing has been found by the guess_payload_class() method.(   RV  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  f  s    c         C   sk   xW |  i  i   D]F } |  i i |  o- |  i | |  i  | j o |  i  | =qV q q W|  i i   d S(   s;   Removes fields' values that are the same as default values.N(   RC  RQ   RN  R  R  t   hide_defaults(   R   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  j  s     c         K   sv   |  i    } d | _ | | _ |  i | _ |  i | _ |  i i   | _ |  i | _ | d  j	 o | i	 |  n | S(   Ni   (
   R   Ra  RC  R   Ri  RI  R  RV  R   R  (   R   R  RA   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   clone_withr  s    		c            s   |    f d    |  i  o g  } |  i } nm g  } t i |  i i   |  i i    D]' \ } } t | t  o | | qX qX ~ |  i i	   } h  }   | |  S(   Nc         3   sH  |  o |  i    } | i |  } t | t  p6 | i |  i o t | g  } qh t |  } n x | D]0 } | | | <x   |  |  D] } | Vq Wqo Wn t | i t  o d  g } n
 | i } xq | D]i } | i
   }	 x: |	 D]2 }
 t |	 |
 t  o |	 |
 i   |	 |
 <q q W| i d | |	  } | Vq Wd  S(   NR  (   R  Rb  R`   R!  R  R+  R"  R  RR  R   R  R  R  R  (   R  t   doneR   t   eltnameR5  R|   R6   t   payloadsR  t   done2RR   R   (   R  (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s2     
 	  (
   Ra  RC  t	   itertoolst   chainRN  R  RO  R`   R  RQ   (   R   R  R  R  RR   R
  (    (   R  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRP     s    
1c         C   sO   t  | t  o | |  j  Sn. t |  t j o d Sn t |  | f   d S(   s6   True if other is an answer from self (self ==> other).i   N(   R`   R(  R   R   R4  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __gt__  s
    c         C   sR   t  | t  o |  i |  Sn. t |  t j o d Sn t |  | f   d S(   s6   True if self is an answer from other (other ==> self).i   N(   R`   R(  R  R   R   R4  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __lt__  s
    c         C   s   t  | |  i  p t Sn xV |  i D]K } | | i j o t Sn |  i | i  | i | i  j o t Sq% q% W|  i | i j S(   N(   R`   R   RZ   Rc  Rb  R  R  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    
 %c         C   s   |  i  |  S(   N(   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __ne__  s    c         C   s   |  i  i   S(   sK   DEV: returns a string that has the same value for a request and its answer.(   R  t   hashret(   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s.   | i  |  i  j o |  i i | i  Sn d S(   s)   DEV: true if self is an answer from otheri    (   R   R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   |  i  | j p |  i  i | j o d Sn x |  i D] } |  i | i  } | d j o q5 n | i p t | d d } n x@ | D]8 } t | t	  o" | i
 |  } | o | Sq q q Wq5 W|  i i
 |  S(   sX   true if self has a layer that is an instance of cls. Superseded by "cls in self" syntax.i   R#  i    N(   R   R   RQ  Rb  R  R   R+  R"  R`   R(  R<  R  (   R   R  R   t
   fvalue_gent   fvalueR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR<    s     #
 
 c         C   s  t  |  t j o) d | j o | i d d  \ } } n | d } } |  i | j p |  i i | j oA | d j o& | d j o |  Sq |  i |  Sq | d 8} n x |  i D] } |  i | i  } | d j o q n | i p t	 | d d } n x_ | D]W } t
 | t  oA g  }	 | i | | d |	 }
 |
 d j	 o |
 Sn |	 d } q
q
Wq W|  i i | | d | S(   s2   Return the nb^th layer that is an instance of cls.R   i   R#  i    t   _trackN(   R   R   Rp   R   R   R  Rb  RQ  R+  R"  R`   R(  RW  R  (   R   R  R    R  t   cclsR.  R   R  R  t   trackR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRW    s2     #
 
 c         C   s   t  |  t j oj | i o |  i | i | i  } n |  i | i  } | d  j o | i d  j	 o | i } n | Sn |  i |  Sd  S(   N(   R   RB  R  RW  R   R   Rh  (   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRF     s    
c         C   s   |  i  |  S(   sK   "cls in self" returns true if self has a layer which is an instance of cls.(   R<  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRC     s    c         O   s   |  i  | |   d S(   s   Deprecated. Use show() method.N(   R  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   
  s    i   c   
   	   C   s  t  i } d | | i d  | i |  i  | i d  f GHxX|  i D]M} t | t  o | i |   o qF n t | t	  o | i
 } | i } n | i } | i } |  i | i  } t | t  p' | i o~ | i ot t |  t j oa d | | | | i  f GHt | d d }	 xm |	 D]$ } | i d | d | | d	  q*WqF d
 | | | | i  | i d  | | i |  |   f GHqF W|  i i d | d | d | |  i d |  d S(   s`   Prints a hierarchical view of the packet. "indent" gives the size of indentation for each layer.s
   %s%s %s %ss   ###[s   ]###s   %s  \%-10s\R#  i    t   indentt	   label_lvls      |s   %s  %-10s%s %sRg  R  RT   N(   R   R   R>  Rl  R  Rc  R`   R6  R8  R-  Rh  Ri  Rj  Rk  Rb  R(  R+  R,  R   R   R"  R  R"  R  t   show_indent(
   R   R  R  R  R  R   Rm  Rn  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s4    	
 !			7 &
c         C   s   |  i  t |    i   d S(   s{   Prints a hierarchical view of an assembled version of the packet, so that automatic fields are calculated (checksums, etc.)N(   R   R   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   show2)  s    c         C   sK  h  d d <d d <d d <} xd | j o| i  d  } | | d i d  } | | d | | d !} | i d  } | d j  o t d	 |   n | |  | | d } } t }	 | d d
 j o t }	 | d } n |  i |  o |	 }	 n |	 p
 d } n | |  | | | | d } q$ Wd }
 xd | j o| i d  } |
 | |  7}
 | | d } | o4 | d | j o# |
 | | d 7}
 | d } q<n y | i d  } | |  } | i d  } t |  d j o d } | d } n* t |  d j o | \ } } n t  d | j o | i d  \ } } n |  i	 i
 } | } d } d | j o% | i d  \ } } t |  } n | | d } Wn, t d | d  | d o d f   q<X| d j o@ t i d t i |  i   t |  i t |  i  d  } n| |  i	 i
 j o t |  |  o | d j o3 |  i i d | | | d | f |  } d } q&| d d j o. t |  |  } | d  } | p
 d } qq&t |  |  } | |  i j o |  i | i |  |  } q&n  |  i i d | |  } d } |
 d | | 7}
 q<W|
 | 7}
 |
 S(   ss  sprintf(format, [relax=1]) -> str
where format is a string that can include directives. A directive begins and
ends by % and has the following format %[fmt[r],][cls[:nb].]field%.

fmt is a classic printf directive, "r" can be appended for raw substitution
(ex: IP.flags=0x18 instead of SA), nb is the number of the layer we want
(ex: for IP/IP packets, IP:2.src is the src of the upper IP layer).
Special case : "%.time%" is the creation time.
Ex : p.sprintf("%.time% %-15s,IP.src% -> %-15s,IP.dst% %IP.chksum% "
               "%03xr,IP.proto% %r,TCP.flags%")

Moreover, the format string can include conditionnal statements. A conditionnal
statement looks like : {layer:string} where layer is a layer name, and string
is the string to insert in place of the condition if it is true, i.e. if layer
is present. If layer is preceded by a "!", the result si inverted. Conditions
can be imbricated. A valid statement can be :
  p.sprintf("This is a{TCP: TCP}{UDP: UDP}{ICMP:n ICMP} packet")
  p.sprintf("{IP:%IP.dst% {ICMP:%ICMP.type%}{TCP:%TCP.dport%}}")

A side effect is that, to obtain "{" and "}" characters, you must use
"%(" and "%)".
R   R   t   (R   t   )i   R   i    s8   Bad condition in format string: [%s] (read sprintf doc!)R  R   i   R&  R   R   s   Bad format string [%%%s%s]i   s   ...R   s   %H:%M:%S.%%06ii@B s   %%%s,%s:%s.%s%%iRg   s   %%%s%%(   t   rindexRS  Rm   R   RZ   R[   R<  Rp   Rq   R   R   Rr   R   Rb  t	   localtimeRM  R  RU  RD   RP  R"  (   R   RE  t   relaxt   escapeR   R   R7  RR   R   R  R   t   sfclsfldt   fclsfldR   t   clsfldR  R.  t   numRB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRU  -  s    	
#

)@#)

!
c         C   s   d S(   s3  DEV: can be overloaded to return a string that summarizes the layer.
           Only one mysummary() is used in a whole packet summary: the one of the upper layer,
           except if a mysummary() also returns (as a couple) a list of layers whose
           mysummary() must be called if they are present.R   (    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   mysummary  s    c         C   s   |  i  i d d  \ } } } | o d | } n d } | p |  i | j o= |  i   } t |  t j o | \ } } | | 7} q n | p | o
 d } n | p |  i i } n d | | f } | o | | | f Sn | Sd S(   s&   Prints a one line summary of a packet.t   interni   s    / R   s   %s%sN(   R  R7  R   R  R   Ro   R   (   R   R  t   foundR   t   neededR  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR7    s"    
c         C   s   |  i  i |   S(   s&   Returns the uppest layer of the packet(   R  t	   lastlayer(   R   t   layer(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s"   t  |  i  } | |  |  _ d S(   s@   Reassembles the payload and decode it using another packet classN(   R   R  (   R   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   decode_payload_as  s    c         C   s   d |  i  i i   GH|  i  t |    } x |  i D]t } | i | i  } | d j o
 d } n4 t |  t j o t |  } n d t |  } d | | i f GHq4 Wd GHd S(   sb   Not ready yet. Should give the necessary C code that interfaces with libnet to recreate the packets   libnet_build_%s(i    s   "%s"s   	%s, 		/* %s */s   );N(	   R   R  RJ  R   Rc  Rb  R   R   Rr   (   R   t   detR   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   libnet  s    
 
c         C   s  g  } x |  i  i   D] \ } } |  i |  } t | t  o | i   } nW | i o@ | i o6 t |  t	 j o# d d i
 t t i |   } n t |  } | i d | | f  q Wd |  i i d i
 |  f } |  i i   } | o | d | 7} n | S(   sT   Returns a string representing the command you have to type to obtain the same packets   [%s]R&  s   %s=%ss   %s(%s)s   , R   (   RC  RO   R  R`   R(  t   commandR+  R,  R   R   RU   RN   R  Rf   R   R   R  (   R   R   t   fnt   fvR.  R   t   pc(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s     '#N(U   R   R   R@  R  R   R  Rc  RM  RI  Ri  RG  RT  R  Ra  R  RF  RH  RK  R   RS  R[  RU  R]  R  R  R`  R^  R_  R  Rb  Rx  R   Rc  Rd  Re  Rf  RV   R   Rr  Ro  Rs  Rt  Ru  Rv  Rw  Ry  R{  R'  R|  R  R}  R  R  R{  R  R  R  R  R  R$  R  R  R  R  RP   R  R  R   R  R  R  R<  RW  RF   RC   R   R  R  RU  R  R7  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR(  9  s   																	
					
														
						%				
								i			t   ASN1_Packetc           B   s/   e  Z d Z d Z d    Z d   Z d   Z RS(   c         C   s)   |  i  i   } |  i |  | |  _ d  S(   N(   R?  R+  R[  Rc  (   R   R\  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRS    s    c         C   s   |  i  i |   S(   N(   R?  R'  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRw    s    c         C   s   |  i  i |  |  S(   N(   R?  R$  (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    N(   R   R   R   R?  R*  RS  Rw  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
   		RR  c           B   s7  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 d  Z d   Z d 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 d# d  Z d d d d  Z d   Z d d   Z d!   Z  d"   Z! RS($   c         O   sP   |  i  i d  } | d  j o- t i |   |  _ } t i | | |  n | S(   Nt	   __singl__(   R?   R   R   t   objectR  R  R(  R   (   R  R\   RA   t   singl(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    c         O   s   d  S(   N(    (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   d  S(   N(    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRU    s    c         C   s   t  d   d  S(   Ns'   Can't add payload to NoPayload instance(   R   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   d  S(   N(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR`    s    c         C   s   d  S(   N(    (   R   Ri  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR^    s    c         C   s   d  S(   N(    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR_    s    c         C   s   |  S(   N(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   d S(   NR   (    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    c         C   s   d S(   NR   (    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR      s    c         C   s   t  S(   N(   RZ   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRu    s    i    c         C   s   d S(   NR   (    (   R   Rz  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'    s    c         C   s   | S(   N(    (   R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR|    s    c         C   s
   d g  f S(   NR   (    (   R   Rz  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR}    s    c         C   s   t  |   d  S(   N(   R  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRb  
  s    c         C   s   t  |   d  S(   N(   R  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRx    s    c         C   s   t  |   d  S(   N(   R  (   R   RE   RB   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRc    s    c         C   s   t  |   d  S(   N(   R  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRe    s    c         C   sQ   | |  i  j o |  i  | Sn/ | |  i i  j o |  i i  | Sn
 t |  d  S(   N(   R?   R   R  (   R   RE   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
    c         C   s   d  S(   N(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s
   t  g   S(   N(   RM   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRP     s    c         C   s   t  | t  o t Sn t S(   N(   R`   RR  R[   RZ   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   d S(   NR   (    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  !  s    c         C   s   t  | t  p t  | t  S(   N(   R`   RR  RY  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    c         C   s   d S(   Ni    (    (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR<  %  s    i   c         C   s"   | d  j	 o | i |  n d  S(   N(   R   Rf   (   R   R  R    R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRW  '  s    i   R   c         C   s   d  S(   N(    (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  +  s    c         C   s#   | o d Sn t  d |   d  S(   Ns   ??s   Format not found [%s](   R   (   R   RE  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRU  -  s    c         C   s   d d g  f S(   Ni    R   (    (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR7  2  s    c         C   s   | S(   N(    (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  4  s    c         C   s   d S(   NR   (    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  6  s    N("   R   R   R  R   RU  R  R`  R^  R_  R  RV   R   Ru  R'  R|  R}  Rb  Rx  Rc  Re  R   R  RP   R   R  R  R<  R   RW  R  RU  R7  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRR    s>   																									RV  c           B   s)   e  Z d  Z e d d  g Z d   Z RS(   RV  R!  R   c         C   s   d S(   Ni   (    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  B  s    (   R   R   R  Rf  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV  ?  s   RY  c           B   s   e  Z d  Z d d  Z RS(   RY  i    c         C   s    | o d Sn t  i |   Sd  S(   NR   (   RV  R'  (   R   Rz  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'  K  s    (   R   R   R  R'  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRY  I  s   R  c           B   sP   e  Z d  Z e d  e d  e d d e  g Z d   Z d   Z	 d   Z
 RS(   t   EthernetR  RO  R   i    c         C   s    t  i d |  i  |  i i   S(   NR/   (   R   R   R   R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  V  s    c         C   sB   t  | t  o. |  i | i j o |  i i | i  Sq> n d S(   Ni    (   R`   R  R   R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  X  s    c         C   s   |  i  d  S(   Ns   %src% > %dst% (%type%)(   RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ]  s    (   R   R   R  RA  RD  R  t   ETHER_TYPESRc  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  Q  s   				t   PPPoEc        	   B   sk   e  Z d  Z e d d d  e d d d  e d d h  d d < e d d  e d	 d  g Z d
   Z	 RS(   s   PPP over Ethernett   versioni   i   R   t   codei    t   Sessiont	   sessionidRq   c         C   sT   | | 7} |  i  d  j o6 t  |  d } | d  t i d |  | d } n | S(   Ni   i   s   !H(   Rq   R   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy  h  s
    
&N(
   R   R   R  R  R  RY  RW  R   Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  `  s   t   PPPoEDc        	   B   s   e  Z d  Z e d d d  e d d d  e d d h  d d <d d	 <d
 d <d d <d d < e d d  e d d  g Z RS(   s   PPP over Ethernet DiscoveryR  i   i   R   R  i	   t   PADIt   PADOi   t   PADRi   t   PADSie   t   PADTi   R  i    Rq   N(	   R   R   R  R  R  RY  RW  R   Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  o  s   <t   Dot3c           B   sV   e  Z d  Z e d e  e d e  e d d d  g Z d   Z	 d   Z
 d   Z RS(	   s   802.3R  RO  Rq   R/   c         C   s   |  i  } | |  | | f S(   N(   Rq   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  |  s    	c         C   s+   t  | t  o |  i i | i  Sn d S(   Ni    (   R`   R  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   d |  i  |  i f S(   Ns   802.3 %s > %s(   RO  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    N(   R   R   R  R?  R  t	   ETHER_ANYR  R   Rc  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  w  s   		t   LLCc           B   s8   e  Z d  Z e d d  e d d  e d d  g Z RS(   R
  t   dsapi    t   ssapR  (   R   R   R  RU  RT  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
    s   t   CookedLinuxc           B   sk   e  Z d  Z e d d h  d d <d d < e d d  e d d  e d	 d
 d  e d d e  g Z	 RS(   s   cooked linuxt   pkttypei    t   unicasts
   sent-by-usi   t
   lladdrtypei   t	   lladdrlenRO  R   i   R  i   (
   R   R   R  R  RY  RW  Rn  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   SNAPc           B   s/   e  Z d  Z e d d  e d d e  g Z RS(   R  t   OUIi    R  (   R   R   R  RV  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   Dot1Qc           B   s}   e  Z d  Z e g Z e d d d  e d d d  e d d d  e d d e  g Z d	   Z	 d
   Z
 d   Z d   Z RS(   s   802.1Qt   prioi    i   R  i   t   vlani   R   c         C   se   t  | t  oA |  i | i j o* |  i | i j o |  i i | i  Sqa n |  i i |  Sd S(   Ni    (   R`   R  R   R  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   |  i  d j o t Sn t S(   Ni  (   R   R
  RV  (   R   Rx  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s6   |  i  d j o | |  i   | |  i  f Sn | d  f S(   Ni  (   R   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s8   t  |  i t  o |  i i d  Sn |  i d  Sd  S(   NsA   802.1q %Ether.src% > %Ether.dst% (%Dot1Q.type%) vlan %Dot1Q.vlan%s'   802.1q (%Dot1Q.type%) vlan %Dot1Q.vlan%(   R`   Ri  R  RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R  R  RM  R  R  R  Rc  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   				t   RadioTapc        '   B   s   e  Z d  Z e d d  e d d  e d d. d d d d   e d	 d. d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* g   e d d+ d, d-   g Z RS(/   s   RadioTap dummyR  i    RV  Rq   t
   notdecodeds   @HRw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    t   presentit   TSFTt   Flagst   Ratet   Channelt   FHSSt   dBm_AntSignalt   dBm_AntNoiset   Lock_Qualityt   TX_Attenuationt   dB_TX_Attenuationt   dBm_TX_Powert   Antennat   dB_AntSignalt   dB_AntNoiset   b14t   b15t   b16t   b17t   b18t   b19t   b20t   b21t   b22t   b23t   b24t   b25t   b26t   b27t   b28t   b29t   b30t   ExtR   Rk  c         C   s   |  i  d  S(   i   (   Rq   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(	   R   R   R  RT  Rt  R   R  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   STPc           B   s   e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d e  e d d  e d	 d  e d
 e  e d d  e d d  e d d  e d d  e d d  g Z	 RS(   s   Spanning Tree ProtocolR  i    R  t   bpdutypet	   bpduflagst   rootidt   rootmact   pathcostt   bridgeidt	   bridgemact   portidt   agei   t   maxagei   t	   hellotimei   t   fwddelayi   (
   R   R   R  RW  RT  R?  R	  RZ  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR:    s   t   EAPOLc        	   B   s   e  Z d  Z e d d  e d d d d d d d	 g  e d
 d d  g Z d Z d Z	 d Z
 d Z d Z d   Z d   Z d   Z d   Z RS(   RG  R  i   R   i    t
   EAP_PACKETt   STARTt   LOGOFFt   KEYt   ASFRq   R/   i   i   i   c         C   s   |  i  } | |  | | f S(   N(   Rq   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    	c         C   s   t  |  i  |  i i   S(   N(   R   R   R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   sU   t  | t  oA |  i |  i j o* | i |  i j o |  i i | i  SqQ n d S(   Ni    (   R`   RG  R   RH  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    c         C   s   |  i  d  S(   Ns   EAPOL %EAPOL.type%(   RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    N(   R   R   R  RT  R  R  R   Rc  RH  RI  RJ  RK  RL  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRG    s   			t   EAPc           B   s   e  Z d  Z e d d h  d d <d d <d d <d	 d < e d
 d  e d d  e e d d h  d d <d d < d    g Z d Z	 d Z
 d Z d Z d Z d Z d   Z d   Z RS(   RM  R  i   t   REQUESTi   t   RESPONSEi   t   SUCCESSi   t   FAILURER  i    Rq   R   t   IDR{  c         C   s   |  i  t i t i g j S(    (   R  RM  RP  RQ  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s   t  | t  o |  i |  i j o d Sq |  i |  i j o2 | i |  i j o | i |  i j o d Sq q | i |  i j o d Sq n d S(   Ni    i   (   R`   RM  R  RN  RO  R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   sd   |  i  d  j oL t  |  t  |  } | d  t | d ?d @ t | d @ | d } n | | S(   Ni   i   i   i   (   Rq   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s    6N(   R   R   R  R  RT  RW  R   R6  Rc  RN  RO  RP  RQ  t   TYPE_IDt   TYPE_MD5R  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRM    s   33	R  c           B   s   e  Z d  Z e d d  e d d e  e d d  e d d  e d	 d h  d d
 <d d <d d <d d <d d <d d <d d <d d <d d < e d  e	 d d  e
 d e  e d d  g	 Z d Z d Z d   Z d   Z d    Z RS(!   R  t   hwtypei   t   ptypei   t   hwleni   t   pleni   R  s   who-hasi   s   is-ati   s   RARP-reqs   RARP-repi   s   Dyn-RARP-reqs   Dyn-RAR-repi   s   Dyn-RARP-erri   s	   InARP-reqi	   s	   InARP-repR  t   psrcR  t   hwdsts   0.0.0.0c         C   sY   t  | t  oE |  i |  i j o. | i |  i j o |  i | i j o d SqU n d S(   Ni   i    (   R`   R  R  t   is_att   who_hasRY  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  &  s    c         C   s
   d | f S(   NR   (    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  -  s    c         C   s^   |  i  |  i j o d |  i |  i f Sn0 |  i  |  i j o d |  i |  i f Sn d Sd  S(   Ns   ARP is at %s says %ss   ARP who has %s says %ss$   ARP %ARP.op% %ARP.psrc% > %ARP.pdst%(   R  R[  R  RY  R\  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  /  s
    (   R   R   R  RY  R  R  RT  R  RG  RR  R?  R	  RO  Rc  R\  R[  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   `			R\  c           B   s  e  Z d  Z e d d d  e d d d  e d d  e d d  e d d  e d	 d d
 d d d g  e d d d  e d d  e	 d d e
  e d d  e e d d   e e d d   e d d  g Z d   Z d   Z d d  Z d   Z d   Z d   Z RS(    R\  R  i   R  t   tosi    Rq   R  i   R  i   t   MFt   DFt   evilt   fragi   RQ  i@   R  t   chksumRO  R  s	   127.0.0.1R   R   c         C   s   |  i  } | d  j o; t |  d } t |  i d @d >| d @B | d } n |  i d  j o< t |  t |  } | d  t i d |  | d } n |  i d  j o> t |  } | d  t | d ? t | d @ | d	 } n | | S(
   Ni   i   i   i   s   !Hi
   i   i   i   (	   R  R   Rq   R   R  R   R   Rb  R   (   R   Rc   Rx  R  R   t   ck(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy  H  s    	+&2c         C   s&   |  i  |  i d >} | |  | | f S(   Ni   (   Rq   R  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  U  s    c         C   sx   xq |  D]i } y# | i  t |  | i d f  Wn% t i j
 o } t i |  n X| o t i |  q q Wd  S(   Ni    (   t   sendtoR   R  R4   R   R   R   t   sleep(   R   R   t   slpRc   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  Y  s     #c         C   s   |  i  t i j o: t |  i t  o' |  i i d j o |  i i i   Snx t i	 oM t i
 oC t t |  i  t |  i   t i d |  i   |  i i   Sn! t i d |  i   |  i i   Sd  S(   Ni   i   i   i   i   Rj  (   i   i   i   i   i   (   R  R4   t   IPPROTO_ICMPR`   R  R2  R   R  R   t
   checkIPsrct   checkIPaddrR   R5   RO  R  R   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  a  s    Cc         C   s   t  | t  p d Sn t i o |  i | i j o d Sn |  i t i j o= t  |  i	 t
  o* |  i	 i d j o |  i	 i	 i |  SnL t i o |  i | i j p |  i | i j o d Sn |  i	 i | i	  Sd  S(   Ni    i   i   i   i   i   (   i   i   i   i   i   (   R`   R\  R   Ri  R  RO  R  R4   Rg  R  R2  R   R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  k  s    c         C   s2   |  i  d  } |  i o | d |  i 7} n | S(   Ns   %IP.src% > %IP.dst% %IP.proto%s    frag:%i(   RU  Ra  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  {  s    
N(   R   R   R  R  R   RU  RW  R  RT  R  t	   IP_PROTOSRY  R-  RR  RO  R  Rc  Ry  R  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\  8  s(   			
	R0  c           B   s   e  Z d  Z e d d e  e d d e  e d d  e d d  e d d d	  e d
 d d	  e d d d d  e	 d d  e
 d d  e	 d d  e d h   g Z d   Z d   Z d   Z d   Z RS(   R0  t   sporti   Ra  iP   R  i    t   ackR  i   t   reservedR  i   i   t   FSRPAUECt   windowi    Rb  t   urgptrR   c         C   s  | | 7} |  i  } | d  j of d t |  i d  i |  |  i   d d } | d  t | d >t | d  d @B | d } n |  i d  j o't	 |  i
 t  o |  i
 i d  j	 o |  i
 i d } n t |  } t i d	 t |  i
 i  t |  i
 i  |  i
 i |  } t | |  } | d
  t i d |  | d } qt	 |  i
 t  p t	 |  i
 t  o> t t i |  i
 |  } | d
  t i d |  | d } qt d  n | S(   Ni   R   i   i   i   i   i   i   s   !4s4sHHi   s   !Hi   s3   No IP underlayer to compute checksum. Leaving null.(   R  R   Rq   R  R!  R   R   R   Rb  R`   Ri  R\  R   R   R5   RO  R  R  R   R  t   _IPv6OptionHeadert
   in6_chksumR4   t   IPPROTO_TCPR   (   R   Rc   Rx  R  t   lnt   psdhdrRc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s,    
	06			&&&c         C   sF   t  i o+ t i d |  i |  i A |  i i   Sn |  i i   Sd  S(   NR/   (   R   Rh  R   R   Rk  Ra  R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
+c         C   s   t  | t  p d Sn t i o2 |  i | i j o |  i | i j p d SqT n t | i |  i  d t	 | i
  j o d Sn d S(   Ni    i   i   (   R`   R0  R   Rh  Rk  Ra  R  R  Rl  Rq   R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
*c         C   s_   t  |  i t  o |  i i d  Sn5 t  |  i t  o |  i i d  Sn |  i d  Sd  S(   Ns;   TCP %IP.src%:%TCP.sport% > %IP.dst%:%TCP.dport% %TCP.flags%s?   TCP %IPv6.src%:%TCP.sport% > %IPv6.dst%:%TCP.dport% %TCP.flags%s)   TCP %TCP.sport% > %TCP.dport% %TCP.flags%(   R`   Ri  R\  RU  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    N(   R   R   R  R  t   TCP_SERVICESRZ  R  R   R  RW  RY  R  Rc  Ry  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR0    s    			
R1  c           B   sw   e  Z d  Z e d d e  e d d e  e d d  e d d  g Z d   Z	 d   Z
 d   Z d	   Z d
   Z RS(   R1  Rk  i5   Ra  Rq   Rb  c         C   s  | | 7} |  i  } | d  j o2 t  |  } | d  t i d |  | d } n |  i d  j o't |  i t  o |  i i  d  j	 o |  i i  d } n t  |  } t i d t |  i i	  t |  i i
  |  i i |  } t | |  } | d  t i d |  | d } qt |  i t  p t |  i t  o> t t i |  i |  } | d  t i d |  | d } qt d  n | S(   Ni   s   !Hi   i   s   !4s4sHHi   s3   No IP underlayer to compute checksum. Leaving null.(   Rq   R   R   R   Rb  R`   Ri  R\  R5   RO  R  R  R   R  Rq  Rr  R4   t   IPPROTO_UDPR   (   R   Rc   Rx  R   Rt  Ru  Rc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s,    
	&			&&&c         C   s   |  i  d } | |  | | f S(   Ni   (   Rq   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   |  i  i   S(   N(   R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   sT   t  | t  p d Sn t i o |  i | i j o d SqA n |  i i | i  S(   Ni    (   R`   R1  R   Rh  Ra  Rk  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
c         C   s_   t  |  i t  o |  i i d  Sn5 t  |  i t  o |  i i d  Sn |  i d  Sd  S(   Ns/   UDP %IP.src%:%UDP.sport% > %IP.dst%:%UDP.dport%s3   UDP %IPv6.src%:%UDP.sport% > %IPv6.dst%:%UDP.dport%s   UDP %UDP.sport% > %UDP.dport%(   R`   Ri  R\  RU  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
    N(   R   R   R  R  t   UDP_SERVICESRW  R   RY  Rc  Ry  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR1    s   				s
   echo-replys   dest-unreachs   source-quencht   redirects   echo-requests   router-advertisements   router-solicitations   time-exceededs   parameter-problems   timestamp-requests   timestamp-replys   information-requests   information-responses   address-mask-requests   address-mask-replyR2  c           B   s@  e  Z d  Z e d d e  e d d  e d d  e e d d  d    e e d d  d	    e e	 d
 d  d    e e	 d d  d    e e	 d d  d    e e
 d d  d    e e d d  d    e e d d  d    e e d d  d    g Z d   Z d   Z d   Z d   Z d   Z RS(   R2  R   i   R  i    Rb  R  c         C   s   |  i  d j S(   i    i   i   i   i   i   (   i    i   i   i   i   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R  c         C   s   |  i  d j S(   i    i   i   i   i   i   (   i    i   i   i   i   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   	  s    t   ts_oric         C   s   |  i  d j S(   i   i   (   i   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   
  s    t   ts_rxc         C   s   |  i  d j S(   i   i   (   i   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    t   ts_txc         C   s   |  i  d j S(   i   i   (   i   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    Rc  s   0.0.0.0c         C   s   |  i  d  j S(   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    t   ptrc         C   s   |  i  d  j S(   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    Rm  c         C   s   |  i  d  j S(   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    t   unusedc      	   C   s   |  i  d j S(	   i    i   i   i   i   i   i   i   (   i    i   i   i   i   i   i   i   (   R   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s\   | | 7} |  i  d  j o> t |  } | d  t | d ? t | d @ | d } n | S(   Ni   i   i   i   (   Rb  R   R   R   (   R   Rc   Rx  Rc  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s
    
2c         C   s&   t  i d |  i |  i  |  i i   S(   Nt   HH(   R   R   R  R  R  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   so   t  | t  p d Sn | i |  i f d
 d d d g j o. |  i | i j o |  i | i j o d	 Sn d S(   Ni    i   i   i   i   i   i   i   i   (   i   i    (   i   i   (   i   i   (   i   i   (   R`   R2  R   R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    %c         C   s    |  i  d j o t Sn d  Sd  S(   Ni   i   i   i   i   (   i   i   i   i   i   (   R   t   IPerrorR   (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  $  s    c         C   s8   t  |  i t  o |  i i d  Sn |  i d  Sd  S(   Ns0   ICMP %IP.src% > %IP.dst% %ICMP.type% %ICMP.code%s   ICMP %ICMP.type% %ICMP.code%(   R`   Ri  R\  RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  )  s    N(   R   R   R  R  t	   icmptypesRT  RY  R   R6  R  RO  RV  RZ  Rc  Ry  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR2    s$   					R  c           B   s    e  Z d  Z d   Z d   Z RS(   s
   IP in ICMPc         C   s   t  | t  p d Sn t i d j p |  i | i j or |  i | i j o_ t i d j p? |  i | i j p, t i d j o, |  i t i	 | i  j o |  i
 | i
 j p d Sn |  i i | i  S(   Ni    i   (   R`   R\  R   Rh  R  RO  t	   checkIPIDR  R4   t   htonsR  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  5  s    #,c         C   s   t  i |   S(   N(   R(  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  @  s    (   R   R   R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  3  s   	t   TCPerrorc           B   s    e  Z d  Z d   Z d   Z RS(   s   TCP in ICMPc         C   s   t  | t  p d Sn t i o2 |  i | i j o |  i | i j p d SqT n t i ob |  i d  j	 o |  i | i j o d Sq n |  i	 d  j	 o |  i	 | i	 j o d Sq q n d S(   Ni    i   (
   R`   R0  R   Rh  Rk  Ra  t   check_TCPerror_seqackR  R   Rl  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  F  s    

c         C   s   t  i |   S(   N(   R(  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  U  s    (   R   R   R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  D  s   	t   UDPerrorc           B   s    e  Z d  Z d   Z d   Z RS(   s   UDP in ICMPc         C   sX   t  | t  p d Sn t i o2 |  i | i j o |  i | i j p d SqT n d S(   Ni    i   (   R`   R1  R   Rh  Rk  Ra  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  [  s    
c         C   s   t  i |   S(   N(   R(  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  c  s    (   R   R   R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  Y  s   	t	   ICMPerrorc           B   s    e  Z d  Z d   Z d   Z RS(   s   ICMP in ICMPc         C   s   t  | t  p d Sn |  i | i j o |  i | i j p d Sn |  i d j o6 |  i | i j o |  i | i j o d Sq d Sn d Sd  S(	   Ni    i   i   i   i   i   i   (   i    i   i   i   i   i   (   R`   R2  R   R  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  j  s    c         C   s   t  i |   S(   N(   R(  R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  x  s    (   R   R   R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  h  s   	R  c           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s,   See http://namabiiru.hongo.wide.ad.jp/scapy6s   IPv6 not implemented here.c         O   s   t  i |  i  d  S(   N(   R  R   R  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   ~  s    c         C   s   d S(   Ns   <IPv6: ERROR not implemented>(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    (   R   R   RW  R  R   RV   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  {  s   	Rq  c           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s,   See http://namabiiru.hongo.wide.ad.jp/scapy6s   IPv6 not implemented here.c         O   s   t  i |  i  d  S(   N(   R  R   R  (   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    c         C   s   d S(   Ns   <IPv6: ERROR not implemented>(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV     s    (   R   R   RW  R  R   RV   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRq    s   	t   L2TPc        	   B   sw   e  Z e d  d h  d d < e d d  e d d  e d d  e d d  e d d  e d	 d  g Z d
   Z RS(   t   pkt_typei   R  Rq   t	   tunnel_idi    t
   session_idt   nst   nrt   offsetc         C   sT   |  i  d  j o< t  |  t  |  } | d  t i d |  | d } n | | S(   Ni   s   !Hi   (   Rq   R   R   R   (   R   R   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s    &N(   R   R   R  RW  R   Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   s   Padding Protocols   ROHC small-CID [RFC3095]s   ROHC large-CID [RFC3095]s   Internet Protocol version 4i!   s   OSI Network Layeri#   s   Xerox NS IDPi%   s   DECnet Phase IVi'   t	   Appletalki)   s
   Novell IPXi+   s   Van Jacobson Compressed TCP/IPi-   s    Van Jacobson Uncompressed TCP/IPs   Bridging PDUi1   s   Stream Protocol (ST-II)i3   s   Banyan Vinesi5   s'   reserved (until 1993) [Typo in RFC1172]i7   s   AppleTalk EDDPi9   s   AppleTalk SmartBufferedi;   s   Multi-Link [RFC1717]i=   s   NETBIOS Framingi?   s   Cisco SystemsiA   s   Ascom TimeplexiC   s-   Fujitsu Link Backup and Load Balancing (LBLB)iE   s   DCA Remote LaniG   s)   Serial Data Transport Protocol (PPP-SDTP)iI   s   SNA over 802.2iK   t   SNAiM   s   IPv6 Header CompressioniO   s   KNX Bridging Data [ianp]iQ   s   Encryption [Meyer]iS   s"   Individual Link Encryption [Meyer]iU   s$   Internet Protocol version 6 [Hinden]iW   s   PPP Muxing [RFC3153]iY   s1   Vendor-Specific Network Protocol (VSNP) [RFC3772]i[   s   RTP IPHC Full Header [RFC3544]ia   s!   RTP IPHC Compressed TCP [RFC3544]ic   s%   RTP IPHC Compressed Non TCP [RFC3544]ie   s#   RTP IPHC Compressed UDP 8 [RFC3544]ig   s#   RTP IPHC Compressed RTP 8 [RFC3544]ii   s   Stampede Bridgingio   s   Reserved [Fox]iq   s   MP+ Protocol [Smith]is   s#   reserved (Control Escape) [RFC1661]i}   s+   reserved (compression inefficient [RFC1662]s!   Reserved Until 20-Oct-2000 [IANA]i   i   s   NTCITS IPI [Ungar]i   s   reserved (PPP NLID)i   s.   single link compression in multilink [RFC1962]i   s   compressed datagram [RFC1962]i   s"   reserved (compression inefficient)i   s   802.1d Hello Packetsi  s   IBM Source Routing BPDUi  s   DEC LANBridge100 Spanning Treei  s!   Cisco Discovery Protocol [Sastry]i  s   Netcs Twin Routing [Korfmacher]i	  s)   STP - Scheduled Transfer Protocol [Segal]i  s*   EDP - Extreme Discovery Protocol [Grosser]i  s3   Optical Supervisory Channel Protocol (OSCP)[Prasad]i  i  t   Luxcomi1  s   Sigma Network Systemsi3  s'   Apple Client Server Protocol [Ridenour]i5  s   MPLS Unicast [RFC3032]  i  s   MPLS Multicast [RFC3032]i  s1   IEEE p1284.4 standard - data packets [Batchelder]i  s-   ETSI TETRA Network Protocol Type 1 [Nieminen]i  s-   Multichannel Flow Treatment Protocol [McCann]i  s*   RTP IPHC Compressed TCP No Delta [RFC3544]ic   s    RTP IPHC Context State [RFC3544]ie   s$   RTP IPHC Compressed UDP 16 [RFC3544]ig   s$   RTP IPHC Compressed RTP 16 [RFC3544]ii   s,   Cray Communications Control Protocol [Stage]i@  s1   CDPD Mobile Network Registration Protocol [Quick]i@  s&   Expand accelerator protocol [Rachmani]i@  s   ODSICP NCP [Arvind]i@  s   DOCSIS DLL [Gaedtke]i	@  s,   Cetacean Network Detection Protocol [Siller]i@  s   Stacker LZS [Simpson]i!@  s   RefTek Protocol [Banfill]i#@  s   Fibre Channel [Rajagopal]i%@  s   EMIT Protocols [Eastham]i'@  s(   Vendor-Specific Protocol (VSP) [RFC3772]i[@  s"   Internet Protocol Control Protocoli!  s"   OSI Network Layer Control Protocoli#  s   Xerox NS IDP Control Protocoli%  s    DECnet Phase IV Control Protocoli'  s   Appletalk Control Protocoli)  s   Novell IPX Control Protocoli+  Rm  i-  i/  s   Bridging NCPi1  s    Stream Protocol Control Protocoli3  s   Banyan Vines Control Protocoli5  s   reserved (until 1993)i7  i9  i;  s   Multi-Link Control Protocoli=  s    NETBIOS Framing Control Protocoli?  s   Cisco Systems Control ProtocoliA  iC  s   Fujitsu LBLB Control ProtocoliE  s/   DCA Remote Lan Network Control Protocol (RLNCP)iG  s'   Serial Data Control Protocol (PPP-SDCP)iI  s   SNA over 802.2 Control ProtocoliK  s   SNA Control ProtocoliM  s'   IP6 Header Compression Control ProtocoliO  s$   KNX Bridging Control Protocol [ianp]iQ  s#   Encryption Control Protocol [Meyer]iS  s3   Individual Link Encryption Control Protocol [Meyer]iU  s   IPv6 Control Protovol [Hinden]iW  s%   PPP Muxing Control Protocol [RFC3153]iY  s:   Vendor-Specific Network Control Protocol (VSNCP) [RFC3772]i[  s"   Stampede Bridging Control Protocolio  s   MP+ Control Protocol [Smith]is  iq  s   Not Used - reserved [RFC1661]i}  i  i  s#   NTCITS IPI Control Protocol [Ungar]i  iπ  s6   single link compression in multilink control [RFC1962]i  s&   Compression Control Protocol [RFC1962]i  i  s)   Cisco Discovery Protocol Control [Sastry]i  i	  s   STP - Control Protocol [Segal]i  s7   EDPCP - Extreme Discovery Protocol Ctrl Prtcl [Grosser]i  s/   Apple Client Server Protocol Control [Ridenour]i5  s   MPLSCP [RFC3032]i  s5   IEEE p1284.4 standard - Protocol Control [Batchelder]i  s+   ETSI TETRA TNP1 Control Protocol [Nieminen]i  i  s   Link Control Protocoli!  s    Password Authentication Protocoli#  s   Link Quality Reporti%  s&   Shiva Password Authentication Protocoli'  s    CallBack Control Protocol (CBCP)i)  s4   BACP Bandwidth Allocation Control Protocol [RFC2125]i+  s   BAP [RFC2125]i-  s8   Vendor-Specific Authentication Protocol (VSAP) [RFC3772]i[  s    Container Control Protocol [KEN]i  s+   Challenge Handshake Authentication Protocoli#  s&   RSA Authentication Protocol [Narayana]i%  s,   Extensible Authentication Protocol [RFC2284]i'  s0   Mitsubishi Security Info Exch Ptcl (SIEP) [Seno]i)  s(   Stampede Bridging Authorization Protocolio  s)   Proprietary Authentication Protocol [KEN]i  s/   Proprietary Authentication Protocol [Tackabury]i  s1   Proprietary Node ID Authentication Protocol [KEN]i  t   HDLCc           B   s&   e  Z e d  d  e d d  g Z RS(   t   addressi   t   controli   (   R   R   RU  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  3  s   t   PPP_metaclassc           B   s   e  Z d d   Z RS(   c         O   sc   |  } | o | d d j o
 t  } n | i | | i | i | i  } | i d | | |  | S(   Ni    s   RW  (   R  R  R   t	   __bases__R?   R   (   R   RW  R\   RA   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __call__8  s    
!N(   R   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  7  s   t   PPPc           B   s)   e  Z e Z d  Z e d d e  g Z RS(   s   PPP Link LayerR  i!   (   R   R   R  R  R  R  t
   _PPP_protoRc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  A  s   s   Configure-Requests   Configure-Acks   Configure-Naks   Configure-Rejects   Terminate-Requests   Terminate-Acks   Code-Rejects   Protocol-Rejects   Echo-Requests
   Echo-Replys   Discard-Requests   Reset-Requests	   Reset-Ackt   PPP_Option_metaclassc           B   s#   e  Z h  Z d d   Z d   Z RS(   c         O   sq   |  } | o) t  | d  } |  i i | |   } n | i | | i | i | i  } | i d | | |  | S(   Ni    RW  (   R   t   _known_optionsR   R  R   R  R?   R   (   R   RW  R\   RA   R  RT  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  W  s    !c         C   s   | |  i  | i d i <d  S(   Ni    (   R  Rc  R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   _register_  s    N(   R   R   R  R   R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  U  s   s   IP-Addresses (Deprecated)s   IP-Compression-Protocols
   IP-Addresss   Mobile-IPv4s   Primary-DNS-Addresss   Primary-NBNS-Addressi   s   Secondary-DNS-Addresss   Secondary-NBNS-Addressi   t   PPP_IPCP_Option_metaclassc           B   s   e  Z h  Z RS(    (   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  q  s   t   PPP_IPCP_Optionc        
   B   sh   e  Z e Z d  Z e d d e  e d d d d d d d d   e	 d d	 d
 d   g Z
 d   Z RS(   s   PPP IPCP OptionR   Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   y  s    R   Rk  c         C   s   t  d  |  i d  S(   i    i   (   R  Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   z  s    c         C   s
   d | f S(   NR   (    (   R   Rx  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  {  s    N(   R   R   R  R  R  R  R   t   _PPP_ipcpopttypesRt  Rq  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  u  s   !t"   PPP_IPCP_Specific_Option_metaclassc           B   s   e  Z d    Z RS(   c         C   s2   t  t |   i |  | | |  } t i |  d  S(   N(   R  R  R  R  R  (   R  R  R  Ry   RA  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    !(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ~  s   t   PPP_IPCP_Option_IPAddressc        
   B   sw   e  Z e Z d  Z e d d e  e d d d d d d d d	   e	 d d
  e
 e d d d d   d    g Z RS(   s   PPP IPCP Option: IP AddressR   i   Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    s   0.0.0.0t   garbageR   Rk  c         C   s   |  i  d  S(   i   (   Rq   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s   |  i  d  j S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  R  R  R  Rt  R   RO  R6  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t   PPP_IPCP_Option_DNS1c        
   B   sw   e  Z e Z d  Z e d d e  e d d d d d d d d	   e	 d d
  e
 e d d d d   d    g Z RS(   s   PPP IPCP Option: DNS1 AddressR   i   Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    s   0.0.0.0R  R   Rk  c         C   s   |  i  d  S(   i   (   Rq   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s   |  i  d  j S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  R  R  R  Rt  R   RO  R6  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t   PPP_IPCP_Option_DNS2c        
   B   sw   e  Z e Z d  Z e d d e  e d d d d d d d d	   e	 d d
  e
 e d d d d   d    g Z RS(   s   PPP IPCP Option: DNS2 AddressR   i   Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    s   0.0.0.0R  R   Rk  c         C   s   |  i  d  S(   i   (   Rq   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s   |  i  d  j S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  R  R  R  Rt  R   RO  R6  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t   PPP_IPCP_Option_NBNS1c        
   B   sw   e  Z e Z d  Z e d d e  e d d d d d d d d	   e	 d d
  e
 e d d d d   d    g Z RS(   s   PPP IPCP Option: NBNS1 AddressR   i   Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    s   0.0.0.0R  R   Rk  c         C   s   |  i  d  S(   i   (   Rq   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s   |  i  d  j S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  R  R  R  Rt  R   RO  R6  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t   PPP_IPCP_Option_NBNS2c        
   B   sw   e  Z e Z d  Z e d d e  e d d d d d d d d	   e	 d d
  e
 e d d d d   d    g Z RS(   s   PPP IPCP Option: NBNS2 AddressR   i   Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    s   0.0.0.0R  R   Rk  c         C   s   |  i  d  S(   i   (   Rq   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s   |  i  d  j S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  R  R  R  Rt  R   RO  R6  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t   PPP_IPCPc           B   sb   e  Z e d  d e  e d d  e d d d d d d d	 d
   e d g  e d d   g Z	 RS(   R  i   R  i    Rq   RE  R/   Ru  R   Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    Rk  c         C   s   |  i  d  S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(
   R   R   R  t   _PPP_conftypesRU  Rt  R   Rm  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !R  t   DESEt   PPP_ECP_Option_metaclassc           B   s   e  Z h  Z RS(    (   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   PPP_ECP_Optionc        
   B   sh   e  Z e Z d  Z e d d e  e d d d d d d d d   e	 d d	 d
 d   g Z
 d   Z RS(   s   PPP ECP OptionR   Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R   Rk  c         C   s   t  d  |  i d  S(   i    i   (   R  Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s
   d | f S(   NR   (    (   R   Rx  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    N(   R   R   R  R  R  R  R   t   _PPP_ecpopttypesRt  Rq  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t!   PPP_ECP_Specific_Option_metaclassc           B   s   e  Z d    Z RS(   c         C   s2   t  t |   i |  | | |  } t i |  d  S(   N(   R  R  R  R  R  (   R  R  R  Ry   RA  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    !(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   PPP_ECP_Option_OUIc        
   B   st   e  Z e Z e d  d e  e d d d d d d d d   e d	 d
 d  e	 d d  e
 d d
 d d   g Z RS(   R   i    Rq   Ru  R  RE  Rj  Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R   R   i   RK  Rk  c         C   s   |  i  d  S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  R  R  Rt  R   Rn  RT  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t   PPP_ECPc           B   sb   e  Z e d  d e  e d d  e d d d d d d d	 d
   e d g  e d d   g Z	 RS(   R  i   R  i    Rq   RE  R/   Ru  R   Rw  c         C   s   | d  S(   i   (    (   Rc   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    Rk  c         C   s   |  i  d  S(   i   (   Rq   (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(
   R   R   R  R  RU  Rt  R   Rm  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   !t   DNSc           B   sp  e  Z d  Z e d d  e d d d  e d d d h  d d <d d <d	 d
 < e d d d  e d d d  e d d d  e d d d  e d d d  e d d d h  d d <d d <d d
 <d d <d d <d d < e d d# d  e d d# d  e d d# d  e d d# d   e d d  e	 d d  e	 d d  e	 d  d d  g Z
 d!   Z d"   Z RS($   R  R  i    t   qri   t   opcodei   t   QUERYt   IQUERYt   STATUSi   R  t   tct   rdt   raR   i   t   rcodeR  s   format-errors   server-failures
   name-errors   not-implementedt   refusedi   t   qdcountt   qdt   ancountt   ant   nscountR  t   arcountt   arc         C   s@   t  | t  o0 |  i | i j o |  i d j o | i d j S(   Ni   i    (   R`   R  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s   d d g |  i  } d } |  i  oA d } |  i d j o' t |  i t  o d |  i i } q n> d } |  i d j o' t |  i t  o d |  i i	 } n d | | f S(   Nt   Qryt   AnsR   i    s    "%s"s	   DNS %s%s (
   R  R  R`   R  R  R   R  R  R  R  (   R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    
##N(   R   R   R  RW  R  R  R  R   R  R  Rc  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s(   -H	R  t   ALLt   At   NSt   MDt   CNAMEt   SOAt   MBt   MGt   MRR  t   WKSt   PTRt   HINFOt   MINFOt   MXt   TXTt   RPt   AFSDBt   AAAAi   t   SRVt   A6i&   t   DNAMEt   IXFRt   AXFRi   t   MAILBt   MAILAi   t   INt   CSt   CHt   HSR  c           B   sD   e  Z d  Z d Z e d d  e d d e  e d d e  g Z RS(   s   DNS Question Recordi    R  R   t   qtypei   t   qclass(	   R   R   R  R  R  R  t	   dnsqtypest
   dnsclassesRc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
   R  c        
   B   sn   e  Z d  Z d Z e d d  e d d e  e d d e  e d d  e	 d  e
 d	 d d
 d   g Z RS(   s   DNS Resource Recordi    R  R   R   i   t   rclassRQ  R  R   Rk  c         C   s   |  i  S(    (   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   #  s    (   R   R   R  R  R  R  t   dnstypesR  RZ  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	s   cSct   BOOTPc           B   s  e  Z d  Z e d d h  d d <d d < e d d  e d d  e d	 d
  e d d
  e d d
  e d d
 d d  e d d  e d d  e d d  e d d  e	 d d d  e	 d d d  e	 d d d  e
 d d  g Z d   Z d   Z d   Z d    Z RS(!   R  R  i   t   BOOTREQUESTt	   BOOTREPLYi   t   htypet   hleni   RV  i    t   xidt   secsR  i   s   ???????????????Bt   ciaddrs   0.0.0.0t   yiaddrt   siaddrt   giaddrt   chaddrR   t   16st   snamet   64st   filet   128sR   c         C   s6   |  i  t t   t j o t Sn t i |  |  Sd  S(   N(   R   Rq   t	   dhcpmagict   DHCPR(  R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  9  s    c         C   sY   |  i  t t   t j o7 |  i  t t  } |  i  t t   |  _  | d  f Sn d Sd  S(   NR   (   R   N(   R   Rq   R  R   (   R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  >  s
    c         C   s   t  i d |  i  S(   Nt   L(   R   R   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  F  s    c         C   s(   t  | t  p d Sn |  i | i j S(   Ni    (   R`   R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  H  s    (   R   R   R  R  RT  RZ  RW  R  RO  R  Rf  Rc  R  R  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  (  s(   !			t   discovert   offert   requestt   declineRl  t   nakt   releaset   informt   force_renewt   lease_queryt   lease_unassignedt   lease_unknownt   lease_activeRV  t   subnet_masks   0.0.0.0t	   time_zonet   routert   time_servert   IEN_name_servert   name_servert
   log_servert   cookie_servert
   lpr_servert   hostnamet	   dump_patht   domaint   root_disk_patht   max_dgram_reass_sizei   t   default_ttlt   pmtu_timeouti   t   broadcast_addresst   arp_cache_timeoutt   ether_or_dot3i$   t   tcp_ttlt   tcp_keepalive_intervalt   tcp_keepalive_garbaget
   NIS_domaini(   t
   NIS_servert
   NTP_serveri*   t   vendor_specifict   NetBIOS_serveri,   t   NetBIOS_dist_servert   requested_addri2   t
   lease_timei  t	   server_idi6   t   param_req_listt   max_dhcp_sizei  t   renewal_timei`T  i:   t   rebinding_timei  t   vendor_class_idi<   t	   client_idt   NISplus_domaint   NISplus_servert   SMTP_servert   POP3_serveriF   t   NNTP_servert
   WWW_serveriH   t   Finger_servert
   IRC_serveriJ   t   StreetTalk_servert   StreetTalk_Dir_AssistanceiL   t   relay_agent_InformationiR   s   message-typeRW  t   DHCPOptionsFieldc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   i   c         C   s  g  } x| D] } t  |  t j o t |  d	 j o t i | d  oH t t | d d t  o, t | d d } | i | | d  } n t | d  } d | d | f } t |  d j o | d | d 7} n | i	 |  q | i	 t
 |   q Wd d i |  S(
   Ni   i   i    i   s   %s=%ss    (garbage=%r)s   [%s]RT   (   i   i   (   R   Ro   Rq   t   DHCPRevOptionsR  R`   R  R"  R  Rf   R   RU   (   R   R   R6   R   R
  R   t   vvRg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR"    s     &0c         C   s   d |  i  | |  f S(   NR   (   R   (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$    s    c   
   	   C   s  g  } x| ot  | d  } | d j o | i d  | d } q	 n | d j o | i d  | d } q	 n t |  d j  p! t |  t  | d  d j  o | i |  Pq	 t i |  o t | } t | t  o@ t  | d  } | i | | d | d !f  | | d } qt  | d  } y' | i | | d | d ! \ } } Wn | i |  Pn X| o | i | | f }	 n | i | f }	 | i |	  | | d } q	 t  | d  } | i | | d | d !f  | | d } q	 W| S(   Ni    i   RW  i   RV  i   (	   R   Rf   Rq   RY  R  R`   R   R$  R  (
   R   R   R6   R  Rb   R   R  R   RB   t   otuple(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     sF    


4
'c   
      C   s  t  |  t j o | Sn d } x| D]} t  |  t j o
t |  d	 j o | d  \ } } t | t  o | | } } nn t i |  oL t | \ } }	 |	 d  j o
 | } q |	 i	 | d |	 i
 | |   } n t d |  q( t |  d j o | | d 7} n | t |  7} | t t |   7} | | 7} q( t  |  t j oA t i |  o1 t | d d  j o | t t | d  7} q( t  |  t j o | t |  d 7} q( t  |  t j o | | 7} q( t d |  q( W| S(
   NR   i   i   s   Unknown field option %si   i    Rh   s   Malformed option %s(   i   i   (   R   R   Ro   Rq   R`   Rr   R8  R  R   R#  R  R   R   (
   R   R   R6   R   Rb   R  RB   R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!    s<     &
%#(   R   R   R+  R"  R$  R   R!  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR7    s
   			(R  c           B   s    e  Z d  Z e d d  g Z RS(   s   DHCP optionsR   R   (   R   R   R  R7  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   R  c           B   s   e  Z d  Z e d d d  e d d d d d d d	 g  e d
 d d  e d d d d d d d d d d d g  e d d  e d e  e	 d e  e
 d e  e d d  e d e  g
 Z d   Z d   Z d   Z d  d d  Z RS(!   s   802.11RK  i    i   R   i   t
   Managementt   ControlRN  t   ReservedR  RN  i   s   to-DSs   from-DSR^  t   retrys   pw-mgtR  t   wept   orderRR  t   addr1t   addr2t   addr3t   SCt   addr4c         C   s   |  i  d  S(   NsA   802.11 %Dot11.type% %Dot11.subtype% %Dot11.addr2% > %Dot11.addr1%(   RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  "  s    c         C   sr   |  i  d j o8 |  i d j o( |  i d j o |  i d j o t Sn' |  i d @o t Sn t i |  |  Sd  S(   Ni   i   i   i   i@   (   R   RK  t   Dot11QoSRN  R  R(  R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  $  s
    @c         C   s  t  | t  o |  i d j o |  i i   | i i   j o d Sn | i |  i f d d	 d
 g j o d Sn |  i | i j o
 d j n o |  i i | i  Sqq|  i d j o d Sq|  i d j o |  i i | i  Sq|  i d j o d Sqn d S(   Ni    i   i   i   i   i   i   (   i    i   (   i   i   (   i   i   (	   R`   R  R   RA  RJ  RB  RK  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  +  s    "$i   c         C   s   |  i  d @d j o | o t d  n d  Sn t |  i i t  o\ | p
 t i o |  i i |  n t |  i i t  o | o t d  n d  Sq n |  i  d M_  |  i i |  _ d  S(   Ni@   i    s   No WEP to removes,   Dot11 can't be decrypted. Check conf.wepkey.i(   RN  R   R`   R  RR  R   t   wepkeyt   decrypt(   R   R   t   warn(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ;  s    N(   R   R   R  R  R  R  RW  R?  R	  RJ  RL  R  RM  Rc  R  R  R  R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   *			RF  c           B   se   e  Z d  Z e d d
 d  e d d
 d  e d d
 d  e d d
 d  e d d
  g Z d	   Z RS(   s
   802.11 QoSt   TIDi   t   EOSPi   s
   Ack Policyi   R=  t   TXOPc         C   s@   t  |  i t  o |  i i d @o t Sq0 n t i |  |  S(   Ni@   (   R`   Ri  R  RN  R  R(  R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  R  s    N(   R   R   R  R  R   RT  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRF  K  s   t   res8t   res9s
   short-slott   res11t   res12s	   DSSS-OFDMt   res14t   res15t   ESSt   IBSSt   CFPs   CFP-reqt   privacys   short-preamblet   PBCCt   agilityt   unspecs   auth-expireds   deauth-ST-leavingt
   inactivitys   AP-fulls   class2-from-nonauths   class3-from-nonasss   disas-ST-leavings   ST-not-autht   successt   failures   cannot-support-all-caps   inexist-assos   asso-denieds   algo-unsupporteds   bad-seq-nums   challenge-failureR  s   rate-unsupportedR  c           B   s>   e  Z d  Z e d d  e d d  e d d d e  g Z RS(   s   802.11 BeaconR  i    t   beacon_intervalid   t   capi   (   R   R   R  R  RX  R  t   capability_listRc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  i  s   t   Dot11Eltc           B   s   e  Z d  Z e d d h  d d <d d <d d <d d	 <d
 d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d < e d d& d  d!  e d  d" d# d$   g Z d%   Z RS('   s   802.11 Information ElementRR  i    t   SSIDt   Ratesi   t   FHseti   t   DSseti   t   CFseti   t   TIMi   t   IBSSseti   t	   challengei   t   ERPinfoi*   s   QoS Capabilityi.   i/   t   RSNinfoi0   t   ESRatesi2   t   vendori   Rm  iD   Rq   Ru   Rj  R   Rk  c         C   s   |  i  S(    (   Rq   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   u  s    c         C   s6   |  i  d j o d t |  i  t g f Sn d Sd  S(   Ni    s   SSID=%sR   (   RR  R  Ru   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  v  s    N(	   R   R   R  R  Rt  R   Rq  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR`  p  s   UAt	   Dot11ATIMc           B   s   e  Z d  Z RS(   s   802.11 ATIM(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRm  |  s   t
   Dot11Disasc           B   s#   e  Z d  Z e d d e  g Z RS(   s   802.11 Disassociationt   reasoni   (   R   R   R  R  t   reason_codeRc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRn    s   t   Dot11AssoReqc           B   s2   e  Z d  Z e d d d e  e d d  g Z RS(   s   802.11 Association RequestR^  i    i   t   listen_intervali   (   R   R   R  R  R_  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRq    s   t   Dot11AssoRespc           B   s>   e  Z d  Z e d d d e  e d d  e d d  g Z RS(   s   802.11 Association ResponseR^  i    i   t   statust   AID(   R   R   R  R  R_  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRs    s   t   Dot11ReassoReqc           B   s>   e  Z d  Z e d d d e  e d e  e d d  g Z RS(   s   802.11 Reassociation RequestR^  i    i   t
   current_APRr  i   (	   R   R   R  R  R_  R?  R	  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRv    s   t   Dot11ReassoRespc           B   s   e  Z d  Z RS(   s   802.11 Reassociation Response(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRx    s   t   Dot11ProbeReqc           B   s   e  Z d  Z RS(   s   802.11 Probe Request(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s   t   Dot11ProbeRespc           B   s>   e  Z d  Z e d d  e d d  e d d d e  g Z RS(   s   802.11 Probe ResponseR  i    R]  id   R^  i   (   R   R   R  R  RX  R  R_  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRz    s   t	   Dot11Authc           B   sM   e  Z d  Z e d d d d g  e d d  e d d e  g Z d   Z RS(   s   802.11 Authenticationt   algoi    Rl   t	   sharedkeyt   seqnumRt  c         C   s#   |  i  | i  d j o d Sn d S(   Ni   i    (   R~  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (   R   R   R  R  RX  t   status_codeRc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR{    s
   t   Dot11Deauthc           B   s#   e  Z d  Z e d d e  g Z RS(   s   802.11 DeauthenticationRo  i   (   R   R   R  R  Rp  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   R  c           B   st   e  Z d  Z e d d d  e d d  e d d d d e d	 d  g Z d
   Z	 d   Z
 d   Z d d  Z RS(   s   802.11 WEP packett   ivt      i   t   keyidi    t   wepdataR  i   t   icvc         C   s   |  i    d  S(   N(   RH  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s%   |  i  d  j o t i |   Sn d S(   NR   (   R  R   R(  R{  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR{    s    c         C   s   |  i  d  j o t i } | ox |  i d  j o& | t i d t |   7} d } n | d d !} t i	 |  i
 |  } | d  | i |  | } q t d  n | S(   Ns   <IR   i   i   s9   No WEP key set (conf.wepkey).. strange results expected..(   R  R   R   RG  R  R   R   t   crc32R3   t   newR  t   encryptR   (   R   Rc   Rx  R   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s    	
c         C   s^   | d  j o t i } n | o9 t i |  i |  } |  i t | i |  i	    n d  S(   N(
   R   R   RG  R3   R  R  R  R
  RH  R  (   R   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRH    s
    N(   R   R   R  Rn  RT  Rf  R   RZ  Rc  R  R{  Ry  RH  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   			t   PrismHeaderc        -   B   s*  e  Z d  Z d Z e d d  e d d  e d d d  e d	 d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d  d
  e d! d
  e d" d
  e d# d
  e d$ d
  e d% d
  e d& d
  e d' d
  e d( d
  e d) d
  e d* d
  e d+ d
  e d, d
  e d- d
  e d. d
  e d/ d
  e d0 d
  e d1 d
  g+ Z d2   Z	 RS(3   s    iwpriv wlan0 monitor 3 s   Prism headert   msgcodeiD   Rq   i   Ri  R   i   t   hosttime_didi    t   hosttime_statust   hosttime_lent   hosttimet   mactime_didt   mactime_statust   mactime_lent   mactimet   channel_didt   channel_statust   channel_lent   channelt   rssi_didt   rssi_statust   rssi_lent   rssit   sq_didt	   sq_statust   sq_lent   sqt
   signal_didt   signal_statust
   signal_lent   signalt	   noise_didt   noise_statust	   noise_lent   noiset   rate_didt   rate_statust   rate_lent   ratet   istx_didt   istx_statust   istx_lent   istxt
   frmlen_didt   frmlen_statust
   frmlen_lent   frmlenc         C   s;   t  | t  o |  i i | i  Sn |  i i |  Sd  S(   N(   R`   R  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    (
   R   R   RW  R  R\  Rn  RX  R]  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s\   t   HSRPc           B   s   e  Z d  Z e d d  e d d h  d d < e d d h  d d < e d d	  e d
 d  e d d  e d d  e d d  e d d d  e d d  g
 Z RS(   R  R  i    R  t   Hellot   statei   t   ActiveRE  i   t   holdtimei
   t   priorityix   t   groupi   Rm  t   autht   ciscoi   t	   virtualIPs   192.168.1.1(   R   R   R  RT  R  Rn  RO  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   NTPc           B   sO  e  Z d  Z e d d d h  d d <d d <d d <d d	 < e d
 d	 d	  e d d	 d	 h  d d <d d <d d <d d	 <d d <d d <d d <d d < e d d d  e d d d  e d d d  e d d d  e d d d  e d  d!  e d" d d#  e d$ d% d#  e d& d d#  e d' d% d#  g Z d(   Z	 RS()   R  t   leapi    i   t	   nowarningt
   longminutei   t   shortminutet   notsynci   R  t   modeRm  t
   sym_activet   sym_passivet   clientR  i   t	   broadcasti   R  i   t   privatei   t   stratumi   t   polli
   t	   precisionRP  i    t
   dispersionR  s	   127.0.0.1R  i@   t   origiRJ  RK  c         C   s   |  i  d  S(   Ns!   NTP v%ir,NTP.version%, %NTP.mode%(   RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  E  s    (
   R   R   R  R  R  R  RO  R  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  '  s6   								t   GREc        	   B   s   e  Z d  Z e d d d  e d d d  e d d d  e d d e  e e d	 d  d
    e e d d  d    g Z	 d   Z
 RS(   R  t   chksumpresenti    i   t	   reserved0i   R  i   R  Rb  c         C   s   |  i  d  j S(   i   (   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   O  s    t	   reserved1c         C   s   |  i  d  j S(   i   (   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   P  s    c         C   sj   | | 7} |  i  oR |  i d  j oB t |  } | d  t | d ?d @ t | d @ | d } n | S(   Ni   i   i   i   (   R  Rb  R   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy  R  s
    
6N(   R   R   R  R  R  R  R6  RY  R   Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  I  s   t   Radiusc           B   s  e  Z d  Z e d d h  d d <d d <d d <d d	 <d
 d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d  d! <d" d# <d$ d% <d& d' <d( d) <d* d+ <d, d- <d. d/ <d0 d1 <d2 d3 <d4 d5 <d6 d7 <d8 d9 <d: d; <d< d= <d> d? <d@ dA <dB dC <dD dE <dF dG <dH dI <dH dJ < e dK dL  e dM dR  e dN dO dP  g Z dQ   Z	 RS(S   R  R  i   s   Access-Requests   Access-Accepti   s   Access-Rejecti   s   Accounting-Requesti   s   Accounting-Accepti   s   Accounting-Statusi   s   Password-Requesti   s   Password-Acki   s   Password-Rejecti	   s   Accounting-Messagei
   s   Access-Challengei   s   Status-Serveri   s   Status-Clienti   s   Resource-Free-Requesti   s   Resource-Free-Responsei   s   Resource-Query-Requesti   s   Resource-Query-Responsei   s"   Alternate-Resource-Reclaim-Requesti   s   NAS-Reboot-Requesti   s   NAS-Reboot-Responsei   s   Next-Passcodei   s   New-Pini   s   Terminate-Sessioni   s   Password-Expiredi    s   Event-Requesti!   s   Event-Responsei"   s   Disconnect-Requesti(   s   Disconnect-ACKi)   s   Disconnect-NAKi*   s   CoA-Requesti+   s   CoA-ACKi,   s   CoA-NAKi-   s   IP-Address-Allocatei2   s   IP-Address-Releasei3   s   Experimental-usei   R=  i   i   R  i    Rq   t   authenticatorR   i   c         C   sV   | | 7} |  i  } | d  j o2 t  |  } | d  t i d |  | d } n | S(   Ni   s   !Hi   (   Rq   R   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s    
	&N(
   R   R   R  R  RT  RW  R   Rn  Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  Z  sT   																																			t   RIPc           B   s   e  Z d  Z e d d h  d d <d d <d d <d d	 <d
 d <d d <d d <d d <d d <d d <d d < e d d  e d d  g Z RS(   s
   RIP headerR  i   t   reqt   respi   t   traceOni   t   traceOffi   t   suni   t   trigReqi   t   trigRespi   t   trigAcki   t	   updateReqi	   t
   updateRespi
   t	   updateAcki   R  t   nulli    (   R   R   R  R  RT  RW  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   :$t   RIPEntryc           B   st   e  Z d  Z e d d h  d d < e d d  e d d  e d d  e d	 d  e d
 d h  d d < g Z RS(   s	   RIP entryt   AFi   R\  t   RouteTagi    Re  s   0.0.0.0R  t   nextHopt   metrici   t   Unreachi   (   R   R   R  R  RW  RO  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   R   t   SAt   Proposalt	   Transformt   KERR  t   CERTt   CRt   SIGt   Noncet   Notificationt   Deletet   VendorIDR_  s   identity prot.s	   auth onlyt
   aggressiveRu   t   ISAKMP_classc           B   s   e  Z d    Z RS(   c         C   s^   |  i  } | d j o t Sn= | t t  j  o% t | } t   i d | t  Sn t Sd  S(   Ni    s   ISAKMP_payload_%s(   t   next_payloadRV  Rq   t   ISAKMP_payload_typet   globalsR   t   ISAKMP_payload(   R   R  t   npR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    	
(   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ISAKMPc           B   s   e  Z d  Z e d d d  e d d d  e d d e  e d d  e d	 d e  e d
 d d d d d d d d d d g  e	 d d  e	 d d  g Z d   Z d   Z d   Z RS(   R  t   init_cookieR   i   t   resp_cookieR  i    R  i   t	   exch_typeR  t
   encryptiont   committ	   auth_onlyt   res3t   res4t   res5t   res6t   res7R  Ro  c         C   s&   |  i  d @o t Sn t i |  |  S(   Ni   (   R  RV  R  R  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   s3   t  | t  o | i |  i j o d Sq/ n d S(   Ni   i    (   R`   R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s    c         C   sJ   | | 7} |  i  d  j o, | d  t i d t |   | d } n | S(   Ni   s   !Ii   (   Ro  R   R   R   Rq   (   R   Rc   Rx  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s    
,N(   R   R   R  Rn  R  R  RU  t   ISAKMP_exchange_typeR  RZ  R   Rc  R  R  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   *		t   ISAKMP_payload_Transformc           B   s   e  Z d  Z e d d e  e d d  e d d  e d d  e d d h  d d < e d	 d  e d
 d d d   g Z	 d   Z
 RS(   s   IKE TransformR  R  i    Ro  R  R  i   t   KEY_IKEt   res2t
   transformsRk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s`   |  i  d  j oB t |  } | d  t | d ?d @ t | d @ | d } n | | 7} | S(   Ni   i   i   i   (   Ro  R   Rq   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy    s
    6
N(   R   R   R  R  R   R  RT  RW  R  Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   	t   ISAKMP_payload_Proposalc           B   s   e  Z d  Z e d d e  e d d  e d d d d d d   e d	 d
  e d d
 h  d d
 < e d d d d  e d d  e d d d d   e	 d e
   e d d   g	 Z RS(   s   IKE proposalR  R  i    Ro  R   R/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    t   proposali   R  R  t   SPIsizet   SPIRj  t   trans_nbR   Rk  c         C   s   |  i  S(    (   R  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  R   R  RT  Rt  Rq  Rj  RV  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
    s   R  c        	   B   s_   e  Z d  Z e d d e  e d d  e d d d d d d   e d d	 d
 d   g Z	 RS(   s   ISAKMP payloadR  R  i    Ro  R!  R/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R   Rk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(
   R   R   R  R  R   R  RT  Rt  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s
   t   ISAKMP_payload_VendorIDc        	   B   sw   e  Z d  Z h  h  d d <e <Z e d d e  e d d  e	 d d d d d d	   e
 d d
 d d   g Z RS(   s   ISAKMP Vendor IDi   R  R  i    Ro  t   vendorIDR/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    R   Rk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK     s    N(   R   R   R  R  RI  R  R   R  RT  Rt  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ISAKMP_payload_SAc           B   s   e  Z d  Z h  h  d d <e <Z e d d e  e d d  e	 d d d d d d	   e
 d
 d h  d d < e
 d d h  d d < e d e   e d d   g Z RS(   s	   ISAKMP SAi   R  R  i    Ro  t   propR/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   !  s    t   DOIt   IPSECt	   situationt   identityRk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   $  s    N(   R   R   R  R  RI  R  R   R  RT  Rt  R  Rj  RV  R
  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   t   ISAKMP_payload_Noncec        	   B   sw   e  Z d  Z h  h  d d <e <Z e d d e  e d d  e	 d d d d d d	   e
 d d
 d d   g Z RS(   s   ISAKMP Noncei
   R  R  i    Ro  R!  R/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   -  s    R   Rk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   .  s    N(   R   R   R  R  RI  R  R   R  RT  Rt  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  '  s   t   ISAKMP_payload_KEc        	   B   sw   e  Z d  Z h  h  d d <e <Z e d d e  e d d  e	 d d d d d d	   e
 d d
 d d   g Z RS(   s   ISAKMP Key Exchangei   R  R  i    Ro  R!  R/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   7  s    R   Rk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   8  s    N(   R   R   R  R  RI  R  R   R  RT  Rt  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  1  s   t   ISAKMP_payload_IDc           B   s   e  Z d  Z h  h  d d <e <Z e d d e  e d d  e	 d d d d d d	   e d
 d h  d d <d d < e d d h  d d < e
 d d h  d d < e d d d d   g Z RS(   s   ISAKMP Identificationi   R  R  i    Ro  R!  R/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   A  s    t   IDtypei   t	   IPv4_addrt   Keyi   t   ProtoIDt   Unusedt   PortR   Rk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   F  s    N(   R   R   R  R  RI  R  R   R  RT  Rt  R  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ;  s   !t   ISAKMP_payload_Hashc        	   B   sw   e  Z d  Z h  h  d d <e <Z e d d e  e d d  e	 d d d d d d	   e
 d d
 d d   g Z RS(   s   ISAKMP Hashi   R  R  i    Ro  R!  R/   Rw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   Q  s    R   Rk  c         C   s   |  i  d  S(   i   (   Ro  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   R  s    N(   R   R   R  R  RI  R  R   R  RT  Rt  Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   K  s   s   ISAKMP_payload_%sR  t   KeepAliveMessaget   RegisterMessaget   IpPortMessaget   KeypadButtonMessaget   EnblocCallMessaget   StimulusMessaget   OffHookMessaget   OnHookMessaget   HookFlashMessaget   ForwardStatReqMessaget   SpeedDialStatReqMessaget   LineStatReqMessaget   ConfigStatReqMessaget   TimeDateReqMessaget   ButtonTemplateReqMessaget   VersionReqMessaget   CapabilitiesResMessaget   MediaPortListMessaget   ServerReqMessaget   AlarmMessaget   MulticastMediaReceptionAckt   OpenReceiveChannelAcki"   t   ConnectionStatisticsRest   OffHookWithCgpnMessaget   SoftKeySetReqMessaget   SoftKeyEventMessaget   UnregisterMessaget   SoftKeyTemplateReqMessaget   RegisterTokenReqt   MediaTransmissionFailuret   HeadsetStatusMessaget   MediaResourceNotificationt   RegisterAvailableLinesMessaget   DeviceToUserDataMessagei.   t   DeviceToUserDataResponseMessaget   UpdateCapabilitiesMessagei0   t&   OpenMultiMediaReceiveChannelAckMessaget   ClearConferenceMessaget   ServiceURLStatReqMessaget   FeatureStatReqMessagei4   t   CreateConferenceResMessaget   DeleteConferenceResMessaget   ModifyConferenceResMessaget   AddParticipantResMessagei8   t   AuditConferenceResMessaget   AuditParticipantResMessaget   DeviceToUserDataVersion1Messaget   RegisterAckMessaget   StartToneMessaget   StopToneMessaget   SetRingerMessagei   t   SetLampMessagei   t   SetHkFDetectMessagei   t   SetSpeakerModeMessagei   t   SetMicroModeMessagei   t   StartMediaTransmissioni   t   StopMediaTransmissioni   t   StartMediaReceptioni   t   StopMediaReceptioni   t   CallInfoMessagei   t   ForwardStatMessagei   t   SpeedDialStatMessagei   t   LineStatMessagei   t   ConfigStatMessagei   t   DefineTimeDatei   t   StartSessionTransmissioni   t   StopSessionTransmissioni   t   ButtonTemplateMessagei   t   VersionMessagei   t   DisplayTextMessagei   t   ClearDisplayi   t   CapabilitiesReqMessagei   t   EnunciatorCommandMessagei   t   RegisterRejectMessagei   t   ServerResMessagei   t   Reseti   t   KeepAliveAckMessaget   StartMulticastMediaReceptioni  t   StartMulticastMediaTransmissioni  t   StopMulticastMediaReceptioni  t   StopMulticastMediaTransmissioni  t   OpenReceiveChanneli  t   CloseReceiveChanneli  t   ConnectionStatisticsReqt   SoftKeyTemplateResMessagei  t   SoftKeySetResMessagei	  t   SelectSoftKeysMessagei  t   CallStateMessagei  t   DisplayPromptStatusMessagei  t   ClearPromptStatusMessagei  t   DisplayNotifyMessagei  t   ClearNotifyMessagei  t   ActivateCallPlaneMessagei  t   DeactivateCallPlaneMessagei  t   UnregisterAckMessagei  t   BackSpaceReqMessagei  t   RegisterTokenAcki  t   RegisterTokenRejecti  t'   DeviceToUserDataResponseVersion1MessageiB   t   StartMediaFailureDetectioni  t   DialedNumberMessagei  t   UserToDeviceDataMessagei  t   FeatureStatMessagei  t   DisplayPriNotifyMessagei   t   ClearPriNotifyMessagei!  t   StartAnnouncementMessagei"  t   StopAnnouncementMessagei#  t   AnnouncementFinishMessagei$  t   NotifyDtmfToneMessagei'  t   SendDtmfToneMessagei(  t   SubscribeDtmfPayloadReqMessagei)  t   SubscribeDtmfPayloadResMessagei*  t   SubscribeDtmfPayloadErrMessagei+  t    UnSubscribeDtmfPayloadReqMessagei,  t    UnSubscribeDtmfPayloadResMessagei-  t    UnSubscribeDtmfPayloadErrMessagei.  t   ServiceURLStatMessagei/  t   CallSelectStatMessagei0  t   OpenMultiMediaChannelMessagei1  t   StartMultiMediaTransmissioni2  t   StopMultiMediaTransmissioni3  t   MiscellaneousCommandMessagei4  t   FlowControlCommandMessagei5  t   CloseMultiMediaReceiveChanneli6  t   CreateConferenceReqMessagei7  t   DeleteConferenceReqMessagei8  t   ModifyConferenceReqMessagei9  t   AddParticipantReqMessagei:  t   DropParticipantReqMessagei;  t   AuditConferenceReqMessagei<  t   AuditParticipantReqMessagei=  t   UserToDeviceDataVersion1Messagei?  t   Skinnyc           B   s;   e  Z d  Z e d d  e d d  e d d e  g Z RS(   R  Rq   i    R  R   (   R   R   R  R\  R  t   skinny_messagesRc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR    s   s
   G.711 PCMUt   GSMt   G723t   DVI4t   LPCt   PCMAt   G722t   L16t   QCELPt   CNt   MPAt   G728t   G729t   CelBi   t   JPEGt   nvt   H261i   t   MPVt   MP2Tt   H263t   RTPc           B   s   e  Z d  Z e d d d  e d d d  e d d d  e d d d d	 d
 e d d d  e d d d e  e d d  e	 d d  e	 d d  e
 d
 g  e	 d d  d d   g
 Z RS(   R  R  i   RZ  i    i   t	   extensiont   numsynci   Rv  t   synct   markerR  i   t   sequenceR  t
   sourcesyncR  Rl  c         C   s   |  i  S(    (   R  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK      s    N(   R   R   R  R  R  R   R  t   _rtp_payload_typesRW  RZ  Rr  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   t	   SebekHeadc        	   B   s   e  Z d  Z e d d  e d d  e d d h  d d <d d <d	 d
 <d d < e d d  e d d  e d d  g Z d   Z RS(   s   Sebek headert   magici R  i   R   i    R-  R   i   R4   i   Rl   t   countert   time_sect	   time_usecc         C   s   |  i  d  S(   Ns2   Sebek Header v%SebekHead.version% %SebekHead.type%(   RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR      s    (	   R   R   R  R^  RW  R  RZ  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   t   SebekV1c        
   B   sz   e  Z d  Z e d d  e d d  e d d  e d d d  e d d d	 d
 d e d	 d d d   g Z d   Z	 RS(   s   Sebek v1t   pidi    t   uidt   fdR  R   i   t   data_lengthR  RE  R  Rk  c         C   s   |  i  S(    (   R  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   -   s    c         C   s8   t  |  i t  o |  i i d  Sn |  i d  Sd  S(   Ns-   Sebek v1 %SebekHead.type% (%SebekV1.command%)s   Sebek v1 (%SebekV1.command%)(   R`   Ri  R  RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  .   s    N(
   R   R   R  RZ  Rn  Rt  R   Rq  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  &   s   t   SebekV3c           B   s   e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d d d	  e d
 d d d d e d d d d   g Z d   Z	 RS(   s   Sebek v3t
   parent_pidi    R  R  R  t   inodeR  R   i   R  R  RE  R  Rk  c         C   s   |  i  S(    (   R  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   =   s    c         C   s8   t  |  i t  o |  i i d  Sn |  i d  Sd  S(   Ns?   Sebek v%SebekHead.version% %SebekHead.type% (%SebekV3.command%)s   Sebek v3 (%SebekV3.command%)(   R`   Ri  R  RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  >   s    N(
   R   R   R  RZ  Rn  Rt  R   Rq  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  4   s   t   SebekV2c           B   s   e  Z d    Z RS(   c         C   s8   t  |  i t  o |  i i d  Sn |  i d  Sd  S(   Ns?   Sebek v%SebekHead.version% %SebekHead.type% (%SebekV2.command%)s   Sebek v2 (%SebekV2.command%)(   R`   Ri  R  RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  E   s    (   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  D   s   t   SebekV3Sockc           B   s
  e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d d d	  e d
 d  e d d  e d d  e d d  e d d  e d d h  d d <d d <d d <d d <d d <d d <d d <d	 d  < e d! d e	  g Z
 d"   Z RS(#   s   Sebek v2 socketR  i    R  R  R  R  R  R   i   R  i   t   dips	   127.0.0.1Ra  t   sipRk  t   calli   t   bindi   R  i   t   listeni   t   accepti   t   sendmsgi   t   recvmsgi   Rd  t   recvfromR  c         C   s8   t  |  i t  o |  i i d  Sn |  i d  Sd  S(   NsC   Sebek v%SebekHead.version% %SebekHead.type% (%SebekV3Sock.command%)s'   Sebek v3 socket (%SebekV3Sock.command%)(   R`   Ri  R  RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ^   s    (   R   R   R  RZ  Rn  RO  RW  R  R  Rj  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  K   s&   t   SebekV2Sockc           B   s   e  Z d    Z RS(   c         C   s8   t  |  i t  o |  i i d  Sn |  i d  Sd  S(   NsC   Sebek v%SebekHead.version% %SebekHead.type% (%SebekV2Sock.command%)s'   Sebek v2 socket (%SebekV2Sock.command%)(   R`   Ri  R  RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  e   s    (   R   R   R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  d   s   t   MGCPc           B   s   e  Z d  Z d Z e d d d d  e d d d  e d d	 d d  e d
 d d  e d d d d  e d d d  e d d d d  e d d d  g Z RS(   R  s   Media Gateway Control ProtocolR  t   AUEPRT   it   sep1i   t   transaction_idt   1234567t   sep2t   endpoints   dummy@dummy.nett   sep3R  s   MGCP 1.0 NCS 1.0s   
t   sep4(   R   R   R  t   longnameR  Rn  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  k   s   t   GPRSc           B   s&   e  Z d  Z e d d d d  g Z RS(   t	   GPRSdummyt   dummyR   t   e  i   (   R   R   R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   t   HCI_Hdrc           B   sY   e  Z d  Z e d d h  d d <d d <d d <d d	 <d
 d < g Z d   Z RS(   s
   HCI headerR   i   R  i   t   ACLdatat   SCOdatai   Rh  i   Rl  i   c         C   s   |  i  d  S(   Ns
   HCI %type%(   RU  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R  R  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   Bt   HCI_ACL_Hdrc           B   sA   e  Z d  Z e d d  e d d  e d d  g Z d   Z RS(   s   HCI ACL headert   handlei    R  Rq   c         C   sd   | | 7} |  i  d  j oF t  |  d } | d  t | d @ t | d ?d @ | d } n | S(   Ni   i   i   i   (   Rq   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy     s
    
6N(   R   R   R  RT  RX  R   Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s
   t	   L2CAP_Hdrc           B   sA   e  Z d  Z e d d  e d d h  d d < g Z d   Z RS(   s   L2CAP headerRq   t   cidi    R  i   c         C   sd   | | 7} |  i  d  j oF t  |  d } | d  t | d @ t | d ?d @ | d } n | S(   Ni   i   i   i   (   Rq   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy     s
    
6N(   R   R   R  RX  R   R  Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   t   L2CAP_CmdHdrc           B   s   e  Z d  Z e d d h  d d <d d <d d <d	 d
 <d d <d d <d d <d d <d d <d d <d d < e d d  e d d  g Z d   Z d   Z	 RS(   s   L2CAP command headerR  i   t   reji   t   conn_reqi   t	   conn_respi   t   conf_reqi   t	   conf_respi   t   disconn_reqi   t   disconn_respi   t   echo_reqt	   echo_respi	   t   info_reqi
   t	   info_respi   R  i    Rq   c         C   sd   | | 7} |  i  d  j oF t  |  d } | d  t | d @ t | d ?d @ | d } n | S(   Ni   i   i   i   (   Rq   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy     s
    
6c         C   s   | i  |  i  j or |  i d j o d Sn | i d j oF |  i | i d j o/ | i d j o d Sn |  i i | i  Sq n d S(	   Ni   i   i   i   i   i
   i    (   i   i   i   i   i
   (   R  R  R  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    'N(
   R   R   R  R  RT  RX  R   Rc  Ry  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   (	t   L2CAP_ConnReqc           B   sJ   e  Z d  Z e d d h  d d <d d <d d < e d	 d  g Z RS(
   s   L2CAP Conn Reqt   psmi    t   SDPi   t   RFCOMMi   s   telephony controli   t   scid(   R   R   R  R  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s   *t   L2CAP_ConnRespc           B   sk   e  Z d  Z e d d  e d d  e d d d d d g  e d d d	 d
 d d d g  g Z d   Z RS(   s   L2CAP Conn Respt   dcidi    R 	  t   resultt   no_infot   authen_pendt   author_pendRt  R[  t   pendt   bad_psmt   cr_sec_blockt	   cr_no_memc         C   s   |  i  | i  j S(   N(   R 	  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R  RX  R  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	     s   t   L2CAP_CmdRejc           B   s    e  Z d  Z e d d  g Z RS(   s   L2CAP Command RejRo  i    (   R   R   R  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	     s   t   L2CAP_ConfReqc           B   s,   e  Z d  Z e d d  e d d  g Z RS(   s   L2CAP Conf ReqR	  i    R  (   R   R   R  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	     s   t   L2CAP_ConfRespc        	   B   sP   e  Z d  Z e d d  e d d  e d d d d d d g  g Z d	   Z RS(
   s   L2CAP Conf RespR 	  i    R  R	  R[  t   unacceptt   rejectt   unknownc         C   s   |  i  | i  j S(   N(   R 	  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R  RX  R  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	     s
   !t   L2CAP_DisconnReqc           B   s,   e  Z d  Z e d d  e d d  g Z RS(   s   L2CAP Disconn ReqR	  i    R 	  (   R   R   R  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	     s   t   L2CAP_DisconnRespc           B   s5   e  Z d  Z e d d  e d d  g Z d   Z RS(   s   L2CAP Disconn RespR	  i    R 	  c         C   s   |  i  | i  j S(   N(   R 	  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR     s    (   R   R   R  RX  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	     s   t   L2CAP_InfoReqc           B   sA   e  Z d  Z e d d h  d d <d d < e d d  g Z RS(	   s   L2CAP Info ReqR   i    t   CL_MTUi   t	   FEAT_MASKi   R  R   (   R   R   R  R  Rf  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	     s   !t   L2CAP_InfoRespc           B   sJ   e  Z d  Z e d d  e d d d d g  e d d  g Z d   Z RS(	   s   L2CAP Info RespR   i    R	  R[  t   not_suppR  R   c         C   s   |  i  | i  j S(   N(   R   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  
!  s    (   R   R   R  RX  R  Rf  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  !  s
   t
   NetBIOS_DSc           B   s   e  Z d  Z e d d h  d d < e d d  e d d  e d d  e d	 d
  e d d  e d d  e	 d d  e	 d d  g	 Z
 d   Z RS(   s   NetBIOS datagram serviceR   i   t   direct_groupR  i    R  RO  s	   127.0.0.1Rk  i   Rq   t   ofst   srcnameR   RS  c         C   sT   | | 7} |  i  d  j o6 t  |  d } | d  t i d |  | d } n | S(   Ni   i
   s   !Hi   (   Rq   R   R   R   (   R   Rc   Rx  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy  !  s
    
&N(   R   R   R  R  RT  RY  RO  RW  R   Rp  Rc  Ry  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  !  s   t	   IrLAPHeadc        	   B   sG   e  Z d  Z e d d d  e d d d h  d d <d d < g Z RS(	   s    IrDA Link Access Protocol Headert   Addressi   i   t   Typei   i    t   Responset   Command(   R   R   R  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  3!  s   t   IrLAPCommandc           B   st   e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d
 h  d
 d < e d d  g Z RS(   s!   IrDA Link Access Protocol CommandR<  i    s   Format identifiers   Source addresss   Destination addressl    s   Discovery flagsi   s   Slot numberi   t   finalt   Version(   R   R   R  RU  R^  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR!	  9!  s   t   IrLMPc           B   s8   e  Z d  Z e d d  e d d  e d d  g Z RS(   s   IrDA Link Management Protocols   Service hintsi    s   Character sets   Device nameR   (   R   R   R  RY  RU  Rf  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$	  D!  s   t   NBNSQueryRequestc           B   s   e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d  e d
 d  e d d h  d d <d d! <d d" <d d# <d d$ <d d% < e d d  e d d h  d d <d d < e d d h  d  d < g Z RS(&   s   NBNS query requestt   NAME_TRN_IDi    t   FLAGSi  t   QDCOUNTi   t   ANCOUNTt   NSCOUNTt   ARCOUNTt   QUESTION_NAMEt   windowst   SUFFIXiAA  t   workstations   messenger servicei   s   file server servicei   s   domain master browseri  s   domain controlleri  s   browser election servicei  R  t   QUESTION_TYPEi    t   NBt   NBSTATi!   t   QUESTION_CLASSt   INTERNETiDA  iAC  iLB  iMB  iOB  (   R   R   R  RW  Rp  R  RT  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%	  P!  s   E!t   NBNSRequestc           B   s  e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d  e d
 d  e d d h  d d <d d7 <d d8 <d d9 <d d: <d d; < e d d  e d d h  d d <d d < e d d h  d  d < e d! d" h  d# d" < e d$ d h  d d <d d < e d% d h  d  d < e d& d  e d' d(  e d) d d h  d* d <d+ d < e d, d d- h  d. d <d/ d <d0 d- <d1 d < e d2 d d3 h  d4 d < e	 d5 d6  g Z
 RS(<   s   NBNS requestR&	  i    R'	  i)  R(	  i   R)	  R*	  R+	  R,	  R-	  R.	  iAA  R/	  s   messenger servicei   s   file server servicei   s   domain master browseri  s   domain controlleri  s   browser election servicei  R  R0	  i    R1	  R2	  i!   R3	  R4	  t   RR_NAMEi  s%   Label String Pointer to QUESTION_NAMEt   RR_TYPEt   RR_CLASSt   TTLt   RDLENGTHi   R  s   Unique names
   Group names   OWNER NODE TYPEi   s   B nodes   P nodes   M nodes   H nodet   UNUSEDi   R  t
   NB_ADDRESSs	   127.0.0.1iDA  iAC  iLB  iMB  iOB  (   R   R   R  RW  Rp  R  RT  RZ  R  RO  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR5	  a!  s*   E!!$6t   NBNSQueryResponsec           B   s"  e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d  e d
 d  e d d h  d d <d d( <d d) <d d* <d d+ <d d, < e d d  e d d h  d d <d d < e d d h  d  d < e d! d"  e d# d$  e d% d  e d& d'  g Z	 RS(-   s   NBNS query responseR&	  i    R'	  i   R(	  R)	  i   R*	  R+	  R6	  R-	  R.	  iAA  R/	  s   messenger servicei   s   file server servicei   s   domain master browseri  s   domain controlleri  s   browser election servicei  R  R0	  i    R1	  R2	  i!   R3	  R4	  R9	  i R:	  i   t   NB_FLAGSR<	  s	   127.0.0.1iDA  iAC  iLB  iMB  iOB  (
   R   R   R  RW  Rp  R  RT  RZ  RO  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR=	  z!  s    E!t   NBNSQueryResponseNegativec           B   s  e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d  e d
 d  e d d h  d d <d d2 <d d3 <d d4 <d d5 <d d6 < e d d  e d d h  d d <d d < e d d h  d  d < e d! d  e d" d#  e d$ d d h  d% d <d& d < e d' d d( h  d) d <d* d <d+ d( <d, d < e d- d d. h  d/ d < e	 d0 d1  g Z
 RS(7   s   NBNS query response (negative)R&	  i    R'	  i  R(	  R)	  i   R*	  R+	  R6	  R-	  R.	  iAA  R/	  s   messenger servicei   s   file server servicei   s   domain master browseri  s   domain controlleri  s   browser election servicei  R  R7	  i    R1	  R2	  i!   R8	  R4	  R9	  R:	  i   R  s   Unique names
   Group names   OWNER NODE TYPEi   s   B nodes   P nodes   M nodes   H nodeR;	  i   R  R<	  s	   127.0.0.1iDA  iAC  iLB  iMB  iOB  (   R   R   R  RW  Rp  R  RT  RZ  R  RO  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR?	  !  s$   E!$6t   NBNSNodeStatusResponsec           B   s  e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d  e d
 d  e d d h  d d <d d% <d d& <d d' <d d( <d d) < e d d  e d d h  d d <d d < e d d h  d  d < e d! d  e d" d#  e d$ d  g Z RS(*   s   NBNS Node Status ResponseR&	  i    R'	  i   R(	  R)	  i   R*	  R+	  R6	  R-	  R.	  iAA  R/	  s   messenger servicei   s   file server servicei   s   domain master browseri  s   domain controlleri  s   browser election servicei  R  R7	  i!   R1	  i    R2	  R8	  R4	  R9	  R:	  iS   t	   NUM_NAMESiDA  iAC  iLB  iMB  iOB  (	   R   R   R  RW  Rp  R  RT  RZ  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR@	  !  s   E!t   NBNSNodeStatusResponseServicec        
   B   s   e  Z d  Z e d d d  e d d h  d d <d d <d	 d
 <d d <d d <d d < e d d  e d d h  d d < g Z RS(   s!   NBNS Node Status Response Servicet   NETBIOS_NAMEs   WINDOWS         i   R.	  i    R/	  s   messenger servicei   s   file server servicei    s   domain master browseri   s   domain controlleri   s   browser election servicei   t
   NAME_FLAGSi   R;	  R~  (   R   R   R  Rn  R  RT  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRB	  !  s
   Et   NBNSNodeStatusResponseEndc           B   s,   e  Z d  Z e d  e d d d  g Z RS(   s   NBNS Node Status Responset   MAC_ADDRESSt
   STATISTICSi    i9   i   i  (   R   R   R  RD  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRE	  !  s   	t   NBNSWackResponsec           B   s  e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d  e d
 d  e d d h  d d <d d' <d d( <d d) <d d* <d d+ < e d d  e d d h  d d <d d < e d d h  d  d < e d! d"  e d# d"  e d$ d% d&  g Z	 RS(,   s&   NBNS Wait for Acknowledgement ResponseR&	  i    R'	  i  R(	  R)	  i   R*	  R+	  R6	  R-	  R.	  iAA  R/	  s   messenger servicei   s   file server servicei   s   domain master browseri  s   domain controlleri  s   browser election servicei  R  R7	  i    R1	  R2	  i!   R8	  R4	  R9	  i   R:	  t   RDATAi)  i   iDA  iAC  iLB  iMB  iOB  (
   R   R   R  RW  Rp  R  RT  RZ  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRH	  !  s   E!t   NBTDatagramc           B   s"  e  Z d  Z e d d  e d d  e d d  e d d  e d	 d
  e d d  e d d  e d d  e d d h  d d <d d  <d d! <d d" <d d# <d d$ < e d d  e d d  e d d h  d d <d d% <d d& <d d' <d d( <d d) < e d d  g Z RS(*   s   NBT Datagram PacketR	  i   R  i   RR  i    t   SourceIPs	   127.0.0.1t
   SourcePorti   t   Lengthi  t   Offsett
   SourceNameR-	  t   SUFFIX1iAA  R/	  s   messenger servicei   s   file server servicei   s   domain master browseri  s   domain controlleri  s   browser election servicei  R  t   DestinationNamet   SUFFIX2iDA  iAC  iLB  iMB  iOB  iDA  iAC  iLB  iMB  iOB  (	   R   R   R  RT  RW  RO  Rp  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ	  !  s   EEt
   NBTSessionc           B   sw   e  Z d  Z e d d h  d d <d d <d d <d d	 <d
 d <d d < e d d d  e d d d  g Z RS(   s   NBT Session Packett   TYPEi    s   Session Messages   Session Requesti   s   Positive Session Responsei   s   Negative Session Responsei   s   Retarget Session Responsei   s   Session Keepalivei   t   RESERVEDi   t   LENGTHi   (   R   R   R  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRS	  !  s   Et$   SMBNetlogon_Protocol_Response_Headerc        "   B   s  e  Z d  Z e d d d  e d d h  d d < e d d  e d	 d
  e d d  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d
  e d d  e d d
  e d d  e d d
  e d d
  e d d
  e d d
  e d d
  e d d   e d! d"  e d# d
  e d$ d
  e d% d
  e d& d
  e d' d  e d( d)  e d* d"  e d+ d
  g  Z RS(,   s$   SMBNetlogon Protocol Response Headert   Starts   SMBi   R 	  i%   t   Transt   Error_Classi   R=  i    t
   Error_codeR  t   Flags2t   PIDHight	   SignatureR  RJ  t   PIDt   UIDt   MIDt	   WordCounti   t   TotalParamCountt   TotalDataCountip   t   MaxParamCountt   MaxDataCountt   MaxSetupCountt   unused2t   Flags3t   TimeOut1i   t   TimeOut2i   t   unused3t   unused4t   ParamCount2t   ParamOffsett	   DataCountt
   DataOffseti\   t
   SetupCountt   unused5(	   R   R   R  Rn  R  RT  RX  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRW	  !  sB   t   SMBMailSlotc           B   sP   e  Z d  Z e d d  e d d  e d d  e d d  e d d	  g Z RS(
   s   SMB Mail Slot ProtocolR  i   R  t   classi   R:  i   R  s   \MAILSLOT\NET\GETDC660(   R   R   R  RX  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRt	  "  s   t&   SMBNetlogon_Protocol_Response_Tail_SAMc        *   B   s  e  Z d  Z e d d h  d d <d d < e d d  e d d  e d	 d
  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d d  e d  d  e d! d"  e d# d$  e d% d& d$  e d' d(  e d) d*  e d+ d,  e d- d. d$  e d/ d  e d0 d  e d1 d2 d  e d3 d(  e d4 d5  e d6 d(  e d7 d8  e d9 d  e d: d;  e d< d=  e d> d  e d? d  e d@ d  e dA d  e dB dC  e dD d  e dE dF  g( Z RS(G   s'   SMB Netlogon Protocol Response Tail SAMR 	  i   s   SAM logon requesti   s   SAM Active directory ResponseR~  i    t   Data1t   Data2i  t   Data3t   Data4iެ  t   Data5i  t   Data6i
  t   Data7iL7  t   Data8i  t   Data9i}  t   Data10i:  t   Data11is  t   Data12i   t   Data13t   rmfft   Data14t   Data16i  t   Data18i
   t   Data20s
   rmff-win2kt   Data21i   t   Data22i  t   Data23i
  t   Data24s
   RMFF-WIN2Kt   Data25t   Data26t   Data27s   Default-First-Site-Namet   Data28t   Data29i<  t   Data30t   Data31i   t   Data32t   Data33i  t   Data34id   t   Data35t   Data36t   Data37t   Data38t   Data39i   t   Data40t   Data41i  (   R   R   R  R  RT  RW  Rn  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRv	  "  sR   !t'   SMBNetlogon_Protocol_Response_Tail_LM20c           B   s_   e  Z d  Z e d d h  d d < e d d  e d d d  e d	 d
  e d d  g Z RS(   s(   SMB Netlogon Protocol Response Tail LM20R 	  i   s    LM 2.0 Response to logon requestR~  i    t   DblSlashs   \\i   t
   ServerNamet   WINt	   LM20Tokeni  (	   R   R   R  R  RT  Rn  R  RX  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  F"  s   t$   SMBNegociate_Protocol_Request_Headerc           B   s   e  Z d  Z e d d d  e d d h  d d < e d d  e d	 d  e d
 d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  g Z RS(   s$   SMBNegociate Protocol Request HeaderRX	  s   SMBi   R 	  ir   t   SMB_COM_NEGOTIATERZ	  i    R=  R[	  R  i   R\	  R]	  R^	  R  RJ  R_	  i   R`	  Ra	  i   Rb	  t	   ByteCounti   (	   R   R   R  Rn  R  RT  RX  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  O"  s"   t"   SMBNegociate_Protocol_Request_Tailc           B   s,   e  Z d  Z e d d  e d d  g Z RS(   s#   SMB Negociate Protocol Request Tailt   BufferFormati   t
   BufferDatas
   NT LM 0.12(   R   R   R  RT  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  c"  s   t0   SMBNegociate_Protocol_Response_Advanced_Securityc        '   B   s  e  Z d  Z e d d d  e d d h  d d < e d d  e d	 d  e d
 d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d  d!  e d" d#  e d$ d  e d% d&  e	 d' d d  e	 d( d d  e	 d) d d  e	 d* d d  e	 d+ d d,  e d- d.  e d/ d0  e d1 d2  e d3 d  e
 d4 d= d5 d6 d7   e	 d8 d d9  e d5 d: d; d<   g# Z RS(>   s0   SMBNegociate Protocol Response Advanced SecurityRX	  s   SMBi   R 	  ir   R	  RZ	  i    R=  t
   Error_CodeR  i   R\	  R]	  R^	  R  RJ  R_	  i   R`	  Ra	  i   Rb	  i   t   DialectIndexi   t   SecurityModei   t   MaxMpxCounti2   t   MaxNumberVCt   MaxBufferSizei?  t
   MaxRawSizei   t
   SessionKeyt   ServerCapabilitiesi  t   UnixExtensionst	   Reserved2t   ExtendedSecurityt   CompBulkt	   Reserved3i   t   ServerTimeHighl     E, t   ServerTimeLowit   ServerTimeZonei<   t   EncryptionKeyLengthR	  t   SecurityBlobRw  c         C   s   | d  S(   i   (    (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   "  s    t   GUIDi   R   Rk  c         C   s   |  i  d  S(   i   (   R	  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   "  s    N(   R   R   R  Rn  R  RT  RX  R  R\  R  R  R   Rq  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  i"  sH   t*   SMBNegociate_Protocol_Response_No_Securityc        &   B   s  e  Z d  Z e d d d  e d d h  d d < e d d  e d	 d  e d
 d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d  d!  e d" d#  e d$ d  e d% d&  e	 d' d d  e	 d( d d  e	 d) d d  e
 d* d d d+  e	 d, d d-  e d. d/  e d0 d1  e d2 d3  e d4 d5  e d6 d7  e	 d8 d d9  e d: d;  e d< d=  g$ Z RS(>   s*   SMBNegociate Protocol Response No SecurityRX	  s   SMBi   R 	  ir   R	  RZ	  i    R=  R	  R  i   R\	  R]	  R^	  R  RJ  R_	  i   R`	  Ra	  i   Rb	  i   R	  i   R	  i   R	  i2   R	  R	  i?  R	  i   R	  R	  i  R	  R	  R	  R	  t   CBR	  i   R	  l     E, R	  iR	  i<   R	  i   R	  i   t   EncryptionKeyi@   t
   DomainNamet	   WORKGROUPR	  t   RMFF1(   R   R   R  Rn  R  RT  RX  R  R\  R  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  "  sJ   t1   SMBNegociate_Protocol_Response_No_Security_No_Keyc        %   B   s  e  Z d  Z e d d d  e d d h  d d < e d d  e d	 d  e d
 d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d  d!  e d" d#  e d$ d  e d% d&  e	 d' d d  e	 d( d d  e	 d) d d  e
 d* d d d+  e	 d, d d-  e d. d/  e d0 d1  e d2 d3  e d4 d  e d5 d6  e d7 d8  e d9 d:  g# Z RS(;   s1   SMBNegociate Protocol Response No Security No KeyRX	  s   SMBi   R 	  ir   R	  RZ	  i    R=  R	  R  i   R\	  R]	  R^	  R  RJ  R_	  i   R`	  Ra	  i   Rb	  i   R	  i   R	  i   R	  i2   R	  R	  i?  R	  i   R	  R	  i  R	  R	  R	  R	  R	  R	  i   R	  l     E, R	  iR	  i<   R	  R	  i   R	  R	  R	  R	  (   R   R   t   namezRn  R  RT  RX  R  R\  R  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  "  sH   t   SMBSession_Setup_AndX_Requestc        1   B   s  e  Z d  Z e d d d  e d d h  d d < e d d  e d	 d  e d
 d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d h  d d < e d d  e d d  e d d   e d! d"  e d# d  e d$ d  e	 d% dL d&  e d' d  e d( d  e d) d*  e d+ d d  e d, d d-  e d. d d  e d/ d d  e d0 d d*  e d1 d2  e d& d3 d4 d5   e d6 d7  e d8 d9  e d: d;  e d< d;  e d= d  e d> d? h  d@ d? < e dA d  e dB d  e dC d  e dD d  e dE dF  e dG d  e dH dI  e dJ dK  g/ Z RS(M   s   Session Setup AndX RequestRX	  s   SMBi   R 	  is   t   SMB_COM_SESSION_SETUP_ANDXRZ	  i    R=  R	  R  i   R\	  i   R]	  R^	  R  RJ  R_	  R`	  Ra	  i   Rb	  i   t   AndXCommandiu   t   SMB_COM_TREE_CONNECT_ANDXR	  t
   AndXOffseti`   t
   MaxBufferSih  t   MaxMPXCounti2   t   VCNumberR	  t   ANSIPasswordLengtht   ANSIPasswordt   UnicodePasswordLengthR	  R	  i   R	  t	   Reserved4i   R	  R	  t	   Reserved5R	  i#   t   PassRk  c         C   s   |  i  S(    (   R	  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   #  s    t   Accountt   GUESTt   PrimaryDomainR   t   NativeOSs   Windows 4.0t   NativeLanManagert
   WordCount2t   AndXCommand2i   t   SMB_COM_NONEt	   Reserved6t   AndXOffset2Ri	  t   PasswordLengtht
   ByteCount2i   t   Passwordt   Paths   \\WIN2K\IPC$t   Servicet   IPCN(   R   R   R  Rn  R  RT  RX  R  R\  R  R   R  Rq  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  "  s`   t   SMBSession_Setup_AndX_Responsec        !   B   s  e  Z d  Z e d d d  e d d h  d d < e d d  e d	 d  e d
 d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d h  d d < e d d  e d d  e d  d  e d! d"  e d# d$  e d% d$  e d& d'  e d( d  e d) d* h  d+ d* < e d, d  e d- d.  e d/ d  e d0 d1  e d2 d3  e d4 d'  g Z	 RS(5   s   Session Setup AndX ResponseRX	  s   SMBi   R 	  is   R	  RZ	  i    R=  R	  R  i   R\	  i  R]	  R^	  R  RJ  R_	  i   R`	  Ra	  i   Rb	  i   R	  iu   R	  R	  R	  iB   t   ActionR	  i   R	  s   Windows 4.0R	  R	  R   R	  R	  i   R	  R	  R	  iP   t   OptionalSupportR	  i   R	  R	  t   NativeFileSystem(
   R   R   R  Rn  R  RT  RX  R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  #  s@   t   MobileIPc           B   s5   e  Z d  Z e d d h  d d <d d < g Z RS(   s   Mobile IP (RFC3344)R   i   t   RRQt   RRPi   (   R   R   R  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  8#  s   t   MobileIPRRQc        	   B   s_   e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d	 d
 d  g Z RS(   s(   Mobile IP Registration Request (RFC3344)R  i    t   lifetimei   t   homeaddrs   0.0.0.0t   haaddrt   coaddrR  R   R  (   R   R   R  RU  RW  RO  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  <#  s   t   MobileIPRRPc           B   sS   e  Z d  Z e d d  e d d  e d d  e d d  e d d	 d
  g Z RS(   s&   Mobile IP Registration Reply (RFC3344)R  i    R	  i   R	  s   0.0.0.0R	  R  R   R  (   R   R   R  RT  RW  RO  R  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  E#  s   t   MobileIPTunnelDatac           B   s,   e  Z d  Z e d d  e d d  g Z RS(   s'   Mobile IP Tunnel Data Message (RFC3519)t   nexthdri   R  i    (   R   R   R  RT  RW  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  M#  s   t   NetflowHeaderc           B   s    e  Z d  Z e d d  g Z RS(   s   Netflow HeaderR  i   (   R   R   R  RW  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  T#  s   t   NetflowHeaderV1c           B   sD   e  Z d  Z e d d  e d d  e d d  e d d  g Z RS(   s   Netflow Header V1R  i    t	   sysUptimet   unixSecst   unixNanoSeconds(   R   R   R  RW  RZ  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  X#  s
   t   NetflowRecordV1c           B   s   e  Z d  Z e d d  e d d  e d d  e d d  e d d  e d d  e d	 d  e d
 d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  e d d  g Z RS(   s   Netflow Recordt   ipsrcs   0.0.0.0t   ipdstt   nexthopt   inputIfIndexi    t   outpuIfIndext   dpktst   dbytest	   starttimet   endtimet   srcportt   dstportRZ  R  R]  t   padding1t   padding2(   R   R   R  RO  RW  RZ  RT  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR	  `#  s"   R	  t   WRQt   DATAt   ACKR  t   OACKt   TFTPc           B   s#   e  Z d  Z e d d e  g Z RS(   s   TFTP opcodeR  i   (   R   R   R  R  t   TFTP_operationsRc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR

  w#  s   t   TFTP_RRQc           B   s>   e  Z d  Z e d d  e d d  g Z d   Z d   Z RS(   s   TFTP Read RequestRw   R   R  t   octetc         C   s   d S(   Ni    (    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    c         C   s   |  i  d  t g f S(   Ns   RRQ %filename%(   RU  R1  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    (   R   R   R  R  Rc  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  }#  s
   	t   TFTP_WRQc           B   s>   e  Z d  Z e d d  e d d  g Z d   Z d   Z RS(   s   TFTP Write RequestRw   R   R  R
  c         C   s   d S(   Ni    (    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    c         C   s   |  i  d  t g f S(   Ns   WRQ %filename%(   RU  R1  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    (   R   R   R  R  Rc  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s
   	t	   TFTP_DATAc           B   s2   e  Z d  Z e d d  g Z d   Z d   Z RS(   s	   TFTP Datat   blocki    c         C   s   |  i  d j o t | t  S(   Ni   (   R
  R`   R
  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    c         C   s   |  i  d  t g f S(   Ns   DATA %block%(   RU  R1  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    (   R   R   R  RW  Rc  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s   	t   TFTP_Optionc           B   s/   e  Z e d  d  e d d  g Z d   Z RS(   R  R   R   c         C   s
   d | f S(   NR   (    (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    (   R   R   R  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s   t   TFTP_Optionsc           B   s&   e  Z e d  g  e d d   g Z RS(   R   Rk  c         C   s   d  S(   N(   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   #  s    (   R   R   Rm  R
  Rc  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s   t   TFTP_ACKc           B   s2   e  Z d  Z e d d  g Z d   Z d   Z RS(   s   TFTP AckR
  i    c         C   si   t  | t  o |  i | i j SnB t  | t  p  t  | t  p t  | t  o |  i d j Sn d S(   Ni    (   R`   R
  R
  R
  R
  t	   TFTP_OACK(   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s
    0c         C   s   |  i  d  t g f S(   Ns   ACK %block%(   RU  R1  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    (   R   R   R  RW  Rc  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s   	s   Not defineds   File not founds   Access violations    Disk full or allocation exceededs   Illegal TFTP operations   Unknown transfer IDs   File already existss   No such users,   Terminate transfer due to option negotiationt
   TFTP_ERRORc           B   sA   e  Z d  Z e d d e  e d d  g Z d   Z d   Z RS(   s
   TFTP Errort	   errorcodei    t   errormsgR   c         C   s=   t  | t  p- t  | t  p t  | t  p t  | t  S(   N(   R`   R
  R
  R
  R
  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    c         C   s   |  i  d  t g f S(   Ns   ERROR %errorcode%: %errormsg%(   RU  R1  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    (	   R   R   R  R  t   TFTP_Error_CodesR  Rc  R  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s
   	R
  c           B   s   e  Z d  Z g  Z d   Z RS(   s   TFTP Option Ackc         C   s   t  | t  p t  | t  S(   N(   R`   R
  R
  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  #  s    (   R   R   R  Rc  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s   t   ASN1_Class_SNMPc           B   s>   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 RS(	   t   SNMPi   i   i   i   i   i   i   i   (   R   R   R  t   PDU_GETt   PDU_NEXTt   PDU_RESPONSEt   PDU_SETt
   PDU_TRAPv1t   PDU_BULKt
   PDU_INFORMt
   PDU_TRAPv2(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  #  s   t   ASN1_SNMP_PDU_GETc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR#
  #  s   t   ASN1_SNMP_PDU_NEXTc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR$
  #  s   t   ASN1_SNMP_PDU_RESPONSEc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR%
  #  s   t   ASN1_SNMP_PDU_SETc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR&
  #  s   t   ASN1_SNMP_PDU_TRAPv1c           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR'
  #  s   t   ASN1_SNMP_PDU_BULKc           B   s   e  Z e i Z RS(    (   R   R   R
  R 
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR(
  #  s   t   ASN1_SNMP_PDU_INFORMc           B   s   e  Z e i Z RS(    (   R   R   R
  R!
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR)
  #  s   t   ASN1_SNMP_PDU_TRAPv2c           B   s   e  Z e i Z RS(    (   R   R   R
  R"
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR*
  #  s   t   BERcodec_SNMP_PDU_GETc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR+
  #  s   t   BERcodec_SNMP_PDU_NEXTc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR,
  #  s   t   BERcodec_SNMP_PDU_RESPONSEc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR-
   $  s   t   BERcodec_SNMP_PDU_SETc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR.
  $  s   t   BERcodec_SNMP_PDU_TRAPv1c           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR/
  $  s   t   BERcodec_SNMP_PDU_BULKc           B   s   e  Z e i Z RS(    (   R   R   R
  R 
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR0
  	$  s   t   BERcodec_SNMP_PDU_INFORMc           B   s   e  Z e i Z RS(    (   R   R   R
  R!
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR1
  $  s   t   BERcodec_SNMP_PDU_TRAPv2c           B   s   e  Z e i Z RS(    (   R   R   R
  R"
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR2
  $  s   t   ASN1F_SNMP_PDU_GETc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR3
  $  s   t   ASN1F_SNMP_PDU_NEXTc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR4
  $  s   t   ASN1F_SNMP_PDU_RESPONSEc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR5
  $  s   t   ASN1F_SNMP_PDU_SETc           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR6
  $  s   t   ASN1F_SNMP_PDU_TRAPv1c           B   s   e  Z e i Z RS(    (   R   R   R
  R
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR7
  "$  s   t   ASN1F_SNMP_PDU_BULKc           B   s   e  Z e i Z RS(    (   R   R   R
  R 
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR8
  %$  s   t   ASN1F_SNMP_PDU_INFORMc           B   s   e  Z e i Z RS(    (   R   R   R
  R!
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR9
  ($  s   t   ASN1F_SNMP_PDU_TRAPv2c           B   s   e  Z e i Z RS(    (   R   R   R
  R"
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR:
  +$  s   t   no_errort   too_bigt   no_such_namet	   bad_valuet	   read_onlyt   generic_errort	   no_accesst
   wrong_typet   wrong_lengtht   wrong_encodingt   wrong_valuet   no_creationt   inconsistent_valuet   ressource_unavailablet   commit_failedt   undo_failedt   authorization_errort   not_writablet   inconsistent_namet
   cold_startt
   warm_startt	   link_downt   link_upt   auth_failuret   egp_neigh_losst   enterprise_specifict   SNMPvarbindc           B   s8   e  Z e i Z e e d  d  e d e d    Z	 RS(   RI  s   1.3R   i    (
   R   R   R~  R  R*  R4  R3  R(  R  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRU
  P$  s   	t   SNMPgetc           B   sP   e  Z e i Z e e d  d  e d d e  e d d  e	 d g  e
   Z RS(   R  i    R   t   error_indext   varbindlist(   R   R   R~  R  R*  R3
  R,  R.  t
   SNMP_errorR6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRV
  W$  s
   	t   SNMPnextc           B   sP   e  Z e i Z e e d  d  e d d e  e d d  e	 d g  e
   Z RS(   R  i    R   RW
  RX
  (   R   R   R~  R  R*  R4
  R,  R.  RY
  R6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRZ
  _$  s
   	t   SNMPresponsec           B   sP   e  Z e i Z e e d  d  e d d e  e d d  e	 d g  e
   Z RS(   R  i    R   RW
  RX
  (   R   R   R~  R  R*  R5
  R,  R.  RY
  R6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR[
  g$  s
   	t   SNMPsetc           B   sP   e  Z e i Z e e d  d  e d d e  e d d  e	 d g  e
   Z RS(   R  i    R   RW
  RX
  (   R   R   R~  R  R*  R6
  R,  R.  RY
  R6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR\
  o$  s
   	t
   SNMPtrapv1c           B   sw   e  Z e i Z e e d  d  e d d  e d d  e	 d d e
  e d d  e d e    e d	 g  e   Z RS(
   R  i    t
   enterprises   1.3t
   agent_addrR   t   generic_trapt   specific_trapt
   time_stampRX
  (   R   R   R~  R  R*  R7
  R,  R3  R/  R.  t   SNMP_trap_typesR`  R6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR]
  w$  s   	t   SNMPbulkc           B   sM   e  Z e i Z e e d  d  e d d  e d d  e d g  e   Z	 RS(   R  i    t   non_repeaterst   max_repetitionsRX
  (
   R   R   R~  R  R*  R8
  R,  R6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRd
  $  s
   	t
   SNMPinformc           B   sP   e  Z e i Z e e d  d  e d d e  e d d  e	 d g  e
   Z RS(   R  i    R   RW
  RX
  (   R   R   R~  R  R*  R9
  R,  R.  RY
  R6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRg
  $  s
   	t
   SNMPtrapv2c           B   sP   e  Z e i Z e e d  d  e d d e  e d d  e	 d g  e
   Z RS(   R  i    R   RW
  RX
  (   R   R   R~  R  R*  R:
  R,  R.  RY
  R6  RU
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRh
  $  s
   	R
  c           B   s   e  Z e i Z e e d  d h  d d <d d <d d <d d < e d	 d
  e d e	   e	 e
 e e e e e e 
  Z d   Z RS(   R  i   t   v1i    t   v2ct   v2i   t   v3i   t	   communityt   publict   PDUc         C   sb   t  |  i t  oO t  | i t  p& t  | i t  p t  | i t  o |  i i | i i j S(   N(   R`   Ro
  R[
  RV
  RZ
  R\
  R  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  $  s
    (   R   R   R~  R  R*  R4  R.  R/  R>  RV
  RZ
  R[
  R\
  R]
  Rd
  Rg
  Rh
  R?  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  $  s   	3t   ASN1_Class_X509c           B   s&   e  Z d  Z d Z d Z d Z d Z RS(   t   X509i   i   i   i   (   R   R   R  t   CONT0t   CONT1t   CONT2t   CONT3(    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRp
  $  s
   t   ASN1_X509_CONT0c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rr
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRv
  $  s   t   ASN1_X509_CONT1c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rs
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRw
  $  s   t   ASN1_X509_CONT2c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rt
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRx
  $  s   t   ASN1_X509_CONT3c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Ru
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRy
  $  s   t   BERcodec_X509_CONT0c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rr
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRz
  $  s   t   BERcodec_X509_CONT1c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rs
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR{
  $  s   t   BERcodec_X509_CONT2c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rt
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR|
  $  s   t   BERcodec_X509_CONT3c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Ru
  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR}
  $  s   t   ASN1F_X509_CONT0c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rr
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~
  $  s   t   ASN1F_X509_CONT1c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rs
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  $  s   t   ASN1F_X509_CONT2c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Rt
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  $  s   t   ASN1F_X509_CONT3c           B   s   e  Z e i Z RS(    (   R   R   Rp
  Ru
  R)  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  $  s   t   X509RDNc           B   s8   e  Z e i Z e e e d  d  e d d    Z	 RS(   RI  s   2.5.4.6R   R   (
   R   R   R~  R  R*  R5  R4  R3  R0  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  $  s   	t	   X509v3Extc           B   s&   e  Z e i Z e d  e d   Z RS(   RB   i    (   R   R   R~  R  R*  R(  R  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  $  s   	t   X509Certc           B   s2  e  Z e i Z e e e e e d  d    e d d  e e	 d d  e
 d e d    e d g  e  e e d	 e d
   e d e d 
   e d g  e  e e e	 d d  e
 d e d    e d d   e e e d g  e     e e	 d d  e
 d e d    e d d   Z RS(   R  i   t   sni   t	   sign_algos   1.2.840.113549.1.1.5t   sa_valuei    t   issuert
   not_beforeit	   not_afteriQ t   subjectt   pubkey_algos   1.2.840.113549.1.1.1t   pk_valuet   pubkeyR   t	   x509v3extt
   sign_algo2t	   sa2_valuet	   signature(   R   R   R~  R  R*  R4  R"  R~
  R,  R3  R(  R  R6  R
  R2  Ra  R1  R
  R
  R?  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  $  s&   	c         K   sE   | d  j	 o | i |  n |  i |  _ |  i i | | f  d  S(   N(   R   R@   RG  Rf   (   RJ  R   t   __fvalRy  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   bind_bottom_up%  s    c         K   sA   | d  j	 o | i |  n | i i   | _ | | i |  <d  S(   N(   R   R@   RI  R  (   RJ  R   R
  Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   bind_top_down%  s    c         K   sB   | d  j	 o | i |  n t |  | |  t |  | |  d  S(   N(   R   R@   R
  R
  (   RJ  R   R
  Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   bind_layers%  s    c         K   sF   | d  j	 o | i |  n | | d  } t | |  i  |  _ d  S(   Nc         S   s`   |  \ } } | | j o t  Sn x8 | D]0 } | | j p | | | | j o t  Sq( q( Wt S(   N(   R[   RZ   (   RI   R   Ry  R   t   uRR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   do_filter'%  s    "(   R   R@   R"   RG  (   RJ  R   R
  Ry  R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   split_bottom_up$%  s    c         K   s   | d  j	 o | i |  n |  | i j oh | i |  } x8 | D]0 } | | j p | | | | j o d  SqB qB W| i i   | _ | i |  =n d  S(   N(   R   R@   RI  R  (   RJ  R   R
  Ry  t   ofvalRR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   split_top_down0%  s     "c         K   sB   | d  j	 o | i |  n t |  | |  t |  | |  d  S(   N(   R   R@   R
  R
  (   RJ  R   R
  Ry  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   split_layers;%  s    R   R  iz   i   i  R  s   01:80:c2:00:00:03ic  id  R  R  R  R  i   i  Ra  Rk  i  Ra  i   i
  i  i  i{   iD   R   i  RK  i  iM  R  R	  R	  R	  R  i  R	  R  i  c   	      C   s>  | d d d } g  } x|  D]} t  | t i  } t |  | d | } x t |  D] } | i   } | t ` | t ` | t ` | | d j o | t i d M_ n | t i d O_ | | d | t _ t	 d | | | | d | ! } | t i i
 i   | _
 | i |  | i |  q] Wq W| S(   Ni   i   i   R!  i(   R   R\  R  Rq   R   R  Rb  R  Ra  RV  RI  R  Rf   (	   R   t   fragsizeR  Rc   R   R    R   R  Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   fragment%  s*      


"c         C   su   | d  j o
 | } n |  i   } | t ` | t i |  t | |  } | d t i d O_ | t |  |  S(   Nii   (   R   R  R\  R  R  R
  R  (   Rc   t   overlapR
  t   overlap_fragsizeR  t   qfrag(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   overlap_frag%  s    

c         C   s\  h  } t    } x |  D] } | t } t | j o | i |  q n | i d j o( | i d @d j o | i |  q n | i | i | i | i f } | | j o | | i |  q t  | g  | | <q Wg  } g  } x4| i	   D]&} | i
 d    | d } | i d j o | i |  q n | i   } t | j o | t i ` n | t } | i d j p | i d j o t | i  }	 n | i | i d >}	 t   }
 x| d D]	} |	 | i d >j oT |	 | i d >j o( t d |	 | i d >| |
 | f  n | i |  d }
 Pn | t i d j p | t i d j o |	 t | t i  7}	 n! |	 | t i | t i d >7}	 t | j o | t i ` n |
 i | t i i    qW|
 d j o q n | i d M_ | ` | ` | |
 } | i |  q Wt    } x* | D]" } | i | i t |    q)W| | | f S(	   sp   defrag(plist) -> ([not fragmented], [defragmented],
                  [ [bad fragments], [bad fragments], ... ])i    i   c         S   s   t  |  i | i  S(    (   R  Ra  (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   &  s    i   i   s*   Fragment overlap (%i > %i) %r || %r ||  %rNi(   R%  R\  Rf   Ra  R  R  RO  R  R  t
   itervaluesRR  R  RY  Ri  R  Rq   R   R  RV  R   R  Rb  R   R   (   t   plistt   fragst   nofragRc   R   RX   t   defragt   missfragR  t   clenR  R  t   defrag2(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  &  st    	 
$ 

 	 (( 
	  c         C   s  h  } g  } d } x |  D] } | | _  | d 7} t | j o | t } | i d j p | i d @o^ | t } | i | i | i | i f } | | j o | | i |  q | g | | <q q n | i |  q Wg  } g  } x>| i	   D]0}	 |	 i
 d    |	 d } | i d j o | |	 7} q n | i   } t | j o | t i ` n | t } | i d j p | i d j o t | i  }
 n | i | i d >}
 t   } x|	 d D]} |
 | i d >j oQ |
 | i d >j o( t d |
 | i d >| | | f  n | |	 7} d } Pn | t i d j p | t i d j o |
 t | t i  7}
 n! |
 | t i | t i d >7}
 t | j o | t i ` n | i | t i i    qW| d j o q n | i d M_ | ` | ` | | } |	 d i  | _  | i |  q Wg  } x< | D]4 } | i t |   } | i  | _  | i |  q4W| | 7} | | 7} | i
 d    x | D] } | `  qWt |  d	  o d
 |  i } n d } t | d | S(   s8   defrag(plist) -> plist defragmented as much as possible i    i   c         S   s   t  |  i | i  S(    (   R  Ra  (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   [&  s    i   i   s*   Fragment overlap (%i > %i) %r || %r ||  %ric         S   s   t  |  i | i  S(    (   R  t   _defrag_pos(   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   &  s    R4  s   Defragmented %st   DefragmentedR  Ni(   R
  R\  Ra  R  R  RO  R  R  Rf   R
  RR  R  RY  Ri  R  Rq   R   R  RV  R   R  Rb  R   R   RM  R4  R%  (   R
  R
  R"	  R  Rc   R   RX   R
  R
  R  R
  R  R  R
  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   defragmentC&  s     	


 


 	 (
( 
 

 
c         K   sh   t  |   t j oH t |   d j o5 t i d |  d d ! d d j o t |  |  Sn t |  |  S(   Ni   s   !Hi   i    i  (   R   R   Rq   R   R   R  R  (   R   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   Ether_Dot3_Dispatcher&  s    Ji!  i"  i#  iw   i  l   s c c         C   sj   t  |   t j	 o |  i   }  n x@ t |  g g  g  d  \ } } } | o t i |  t  q& Pq& d  S(   Ni    (   R   Rr   t   filenoR&   R   R-  t   MTU(   R  Rg   R   R|   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   flush_fd&  s    !t   SuperSocketc           B   s\   e  Z d  Z e i e i d  d  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z RS(   i    c         C   s1   t  i  | | |  |  _ |  i |  _ d  |  _ d  S(   N(   R4   t   inst   outsR   t   promisc(   R   R
  R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   &  s    c         C   s+   t  |  } t i   | _ |  i i |  S(   N(   R   R   RL  R
  R  (   R   R6   t   sx(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  &  s    c         C   s   t  |  i i |   S(   N(   RV  R
  RJ  (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  &  s    c         C   s   |  i  i   S(   N(   R
  R
  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  &  s    c         C   s   |  i  o d  Sn d |  _  |  i |  i j o5 |  i o' |  i i   d j o |  i i   qc n |  i o' |  i i   d j o |  i i   n d  S(   Ni   i(   t   closedR
  R
  R
  R~   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~   &  s    
	  c         C   s   |  i  i |  d  S(   N(   R
  R  (   R   Re  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   bind_in&  s    c         C   s   |  i  i |  d  S(   N(   R
  R  (   R   Re  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   bind_out&  s    (   R   R   R
  R4   RZ  R  R   R  RJ  R
  R~   R
  R
  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  &  s   						t   L3RawSocketc           B   s2   e  Z e d d d d  d  Z d   Z d   Z RS(   i    c         C   sh   t  i  t  i t  i t  i  |  _ |  i i t  i t  i d  t  i  t  i t  i t  i	 |   |  _
 d  S(   Ni   (   R4   RZ  t   SOCK_RAWt   IPPROTO_RAWR
  R  t   SOL_IPt
   IP_HDRINCLt	   AF_PACKETR  R
  (   R   R   R"   Rd  R
  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   &  s    !c         C   s   t  |  i i |   i S(   N(   R  R
  RJ  R  (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  &  s    c         C   sg   y; t  |  } t i   | _ |  i i | | i d f  Wn% t i j
 o } t i |  n Xd  S(   Ni    (	   R   R   RL  R
  Rd  R  R4   R   R   (   R   R6   R
  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  &  s     N(   R   R   t   ETH_P_IPR   R   RJ  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  &  s   	t   L3PacketSocketc           B   s;   e  Z e d d d d  d  Z d   Z d   Z d   Z RS(   i    c         C   s  | |  _  t i t i t i t i |   |  _ |  i i t i t i d  t	 |  i  | o |  i i
 | | f  n | p^ t i o/ | o d | t i f } q d t i } n | d  j	 o t |  i |  q n |  i i t i t i d  t i t i t i t i |   |  _ |  i i t i t i d  | d  j o t i } n | |  _ |  i on | d  j o t   |  _ n* | i t j o | |  _ n | g |  _ x% |  i D] } t |  i |  qWn d  S(   Ni    s   (%s) and not (%s)s   not (%s)i   i   i   @i   @(   R   R4   R
  R
  R  R
  R  R  t	   SO_RCVBUFR
  R  R   t   except_filterR   R  R
  t	   SO_SNDBUFR
  R  Rs  R   R   R  (   R   R   R"   R
  Rd  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   '  s8    	'
'	

 c         C   sa   |  i  o d  Sn d |  _  |  i o+ x( |  i D] } t |  i | d  q/ Wn t i |   d  S(   Ni   i    (   R
  R
  Rs  R  R
  R
  R~   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~   !'  s    
	

 c         C   sH  |  i  i |  \ } } | d t i j o d  Sn t i | d  o t | d } d } n\ t i | d  o t | d } d } n0 t d | d | d | d f  t	 } d } y | |  } Wn9 t
 j
 o
   n% t i o   n t |  } n X| d j o | i } n | d  j	 o t |  i   | _ n | S(   Ni   i   i   sJ   Unable to guess type (interface=%s protocol=%#x family=%i). Using Etherneti    (   R
  R  R4   t   PACKET_OUTGOINGR   t   LLTypesR  t   L3TypesR   R  R  R   R  RV  R  R  R   (   R   R6   R   t   sa_llR  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  )'  s2    

#
c   
         s  t  | t  o" t i i | i  \ } } } n< t | d  o" t i i | i  \ } } } n
 t i } | |  i f } |  i	 i
 |  |  i	 i     d   }   d t t f j o | t f } n t i   d  o   f d   } n y8 t | |   } t i   | _ |  i	 i | |  Wn t i j
 op } t i   | _ t i oK | d d j o: x: t |  D]% }	 |  i	 i t | |	   |  qwWq  n Xd  S(   NR  c         S   s   |  S(    (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   Q'  s    i   c            s   t    d    |  S(   i   (   R
  (   R6   (   R
  (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   U'  s    i    iZ   (   R`   R  R   RE  Rf  R  RM  Rd  R   R
  R  t   getsocknamet
   ARPHDR_PPPt
   ARPHDR_TUNR
  R
  R  R   R   RL  Rd  R4   R   t   auto_fragmentR
  (
   R   R6   Rs  R  Rc  t   sdtoR  R
  R   Rc   (    (   R
  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  G'  s0    ""		 'N(   R   R   t	   ETH_P_ALLR   R   R~   RJ  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  '  s   		t   L2Socketc           B   s&   e  Z d e d d  d  Z d   Z RS(   i    c         C   s  | d  j o t i } n t i t i t i t i |   |  _ |  i i t i	 t i
 d  t |  i  | p^ t i o/ | o d | t i f } q d t i } n | d  j	 o t |  i |  q n |  i i | | f  |  i i t i	 t i
 d	  |  i |  _ |  i i t i	 t i d
  |  i i   } t i | d  o t | d |  _ nV t i | d  o t | d |  _ n- t d | d | d | d f  t |  _ d  S(   Ni    s   (%s) and not (%s)s   not (%s)i   i   i   i   sJ   Unable to guess type (interface=%s protocol=%#x family=%i). Using Etherneti   @i   @(   R   R   Rd  R4   R
  R
  R  R
  R  R  R
  R
  R
  R  R  R
  R
  R
  R
  R  t   LLR
  R   R  (   R   Rd  R   R"   R  R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   f'  s.    '
#c         C   s   |  i  i |  \ } } | d t i j o d  Sn y |  i |  } Wn9 t j
 o
   n% t i o   n t	 |  } n Xt
 |  i   | _ | S(   Ni   (   R
  R  R4   R
  R   R
  R  R   R  RV  R  R   (   R   R6   R   R
  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  '  s    
N(   R   R   R   R
  R   RJ  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  e'  s   t   L2ListenSocketc           B   s;   e  Z d e d d d  d  Z d   Z d   Z d   Z RS(   i    c         C   s  | |  _  d  |  _ t i t i t i t i |   |  _ |  i i t i	 t i
 d  t |  i  | d  j	 o |  i i | | f  n | p^ t i o/ | o d | t i f } q d t i } n | d  j	 o t |  i |  q n | d  j o t i } n | |  _ | d  j o t   |  _ n* | i t j o | |  _ n | g |  _ |  i o( x% |  i D] } t |  i |  qkWn |  i i t i	 t i
 d  d  S(   Ni    s   (%s) and not (%s)s   not (%s)i   i   i   @(   R   R   R
  R4   R
  R
  R  R
  R  R  R
  R
  R  R   R
  R  t   sniff_promiscR
  R  Rs  R   R   R  (   R   Rd  R   R
  R"   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   '  s6    		'
	

 c         C   sF   |  i  o+ x( |  i D] } t |  i | d  q Wn t i |   d  S(   Ni    (   R
  Rs  R  R
  R
  R~   (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~   '  s
    

 c         C   s   |  i  i |  \ } } t i | d  o t | d } nP t i | d  o t | d } n* t d | d | d | d f  t } y | |  } Wn9 t j
 o
   n% t i	 o   n t
 |  } n Xt |  i   | _ | S(   Ni   i   sJ   Unable to guess type (interface=%s protocol=%#x family=%i). Using Etherneti    (   R
  R  R
  R  R
  R   R  R  R   R  RV  R  R   (   R   R6   R   R
  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  '  s"    #
c         C   s   t  d   d  S(   Ns'   Can't send anything with L2ListenSocket(   R   (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  '  s    N(   R   R   R   R
  R   R~   RJ  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  '  s   		t   L3dnetSocketc           B   sG   e  Z e d d d d  d  Z d   Z e d  Z d   Z d   Z	 RS(   i    c      	   C   sG  h  |  _  t i   |  _ | d  j o t i } n | |  _ |  i i | d d d  y) t |  i i	   t
 t i d d   Wn n X| o% | t j o d | } q"d  } np t i o/ | o d | t i f } q d t i } n | t j o) | o d	 | | f } q"d | } n | o |  i i | d d  n d  S(
   Ni@  i    id   R  i   s   ether proto %is   (%s) and not (%s)s   not (%s)s   (ether proto %i) and (%s)(   t   iflistR  t
   pcapObjectR
  R   R   Rd  t	   open_liveR(   R
  t   BIOCIMMEDIATER   R   R
  R
  t	   setfilter(   R   R   R"   R
  Rd  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   '  s0    		)

c         C   s   t  | t  o" t i i | i  \ } } } n< t | d  o" t i i | i  \ } } } n
 t i } |  i i	 |  } | d  j o t i |  |  i | <} n t t   |  } t i   | _ | i |  d  S(   NR  (   R`   R  R   RE  Rf  R  RM  Rd  R
  R   R   R  t   ethR   R  R   RL  R  (   R   R6   Rs  R  Rc  t   ifsR
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  '  s    ""	c         C   s   |  i  i   } t i |  o t | } n t d |  i | f  t } |  i  i   } | d  j	 o | \ } } } n | d  j o d  Sn y | |  } Wn9 t	 j
 o
   n% t
 i o   n t |  } n X| | _ | i S(   NsH   Unable to guess datalink type (interface=%s linktype=%i). Using Ethernet(   R
  t   datalinkR
  R  R   Rd  R  R   R   R  R   R  RV  R   R  (   R   R6   R  R  R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  '  s(    
	c         C   s0   |  i  i d  |  i   } |  i  i d  | S(   Ni   i    (   R
  t   setnonblockRJ  (   R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nonblock_recv(  s    c         C   s8   t  |  d  o
 |  ` n t  |  d  o
 |  ` n d  S(   NR
  R
  (   RM  R
  R
  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~   (  s    
N(
   R   R   R
  R   R   R  R
  RJ  R
  R~   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  '  s
   		t   L2dnetSocketc           B   s8   e  Z d e d d  d  Z d   Z d   Z d   Z RS(   i    c      	   C   sP  | d  j o t i } n | |  _ t i   |  _ |  i i | d d d  y) t |  i i   t	 t
 i d d   Wn n X| o% | t j o d | } qd  } np t i o/ | o d | t i f } q d t i } n | t j o) | o d	 | | f } qd | } n | o |  i i | d d  n t i |  |  _ d  S(
   Ni@  i    id   R  i   s   ether proto %is   (%s) and not (%s)s   not (%s)s   (ether proto %i) and (%s)(   R   R   Rd  R  R
  R
  R
  R(   R
  R
  R   R   R
  R
  R
  R  R
  R
  (   R   Rd  R   R"   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   !(  s0    	)

c         C   s   |  i  i   } t i |  o t | } n t d |  i | f  t } |  i  i   } | d  j	 o | \ } } } n | d  j o d  Sn y | |  } Wn9 t	 j
 o
   n% t
 i o   n t |  } n X| | _ | S(   NsH   Unable to guess datalink type (interface=%s linktype=%i). Using Ethernet(   R
  R
  R
  R  R   Rd  R  R   R   R  R   R  RV  R   (   R   R6   R  R  R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  >(  s(    
	c         C   s3   |  i  i d  |  i t  } |  i  i d  | S(   Ni   i    (   R
  R
  RJ  R
  (   R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  W(  s    c         C   s8   t  |  d  o
 |  ` n t  |  d  o
 |  ` n d  S(   NR
  R
  (   RM  R
  R
  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~   ](  s    
N(   R   R   R   R
  R   RJ  R
  R~   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
   (  s   		t   L2pcapListenSocketc           B   s8   e  Z d e d d d   Z d   Z d   Z d   Z RS(   c      	   C   s%  | |  _  d  |  _ t i   |  _ | |  _ | d  j o t i } n | d  j o t i } n | |  _	 |  i i
 | d |  i	 d  y) t |  i i   t t i d d   Wn n X| t j o^ t i o/ | o d | t i f } q d t i } n | o |  i i | d d  q!n d  S(   Ni@  id   R  i   s   (%s) and not (%s)s   not (%s)i    (   R   R   R
  R  R
  R
  Rd  R   R
  R
  R
  R(   R
  R
  R   R   R
  R
  R
  (   R   Rd  R   R
  R"   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   h(  s*    				)
c         C   s
   |  `  d  S(   N(   R
  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~   (  s    c         C   s   |  i  i   } t i |  o t | } n t d |  i | f  t } d  } xA | d  j o3 |  i  i   } | d  j	 o | \ } } } qS qS Wy | |  } Wn9 t	 j
 o
   n% t
 i o   n t |  } n X| | _ | S(   NsH   Unable to guess datalink type (interface=%s linktype=%i). Using Ethernet(   R
  R
  R
  R  R   Rd  R  R   R   R  R   R  RV  R   (   R   R6   R  R  R   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  (  s(    
	c         C   s   t  d   d  S(   Ns+   Can't send anything with L2pcapListenSocket(   R   (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  (  s    N(   R   R   R   R
  R   R~   RJ  R  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  g(  s   		t   SimpleSocketc           B   s   e  Z d    Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   R
  R
  (   R   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   (  s    	(   R   R   R   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  (  s   t   StreamSocketc           B   s    e  Z e d   Z e d  Z RS(   c         C   s   t  i |  |  | |  _ d  S(   N(   R
  R   t   basecls(   R   R  R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   (  s    c         C   s   |  i  i | t i  } t |  } |  i |  } | t } | d  j	 o | i d  j	 o | i `	 n x? | d  j	 o1 t
 | t  o  | t | i  8} | i	 } qj W|  i  i |  | S(   N(   R
  RJ  R4   t   MSG_PEEKRq   R
  RY  R   Ri  R  R`   RR  R!  (   R   R6   R   RV  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  (  s    
!(   R   R   RV  R   R
  RJ  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  (  s   t   BluetoothL2CAPSocketc           B   s   e  Z d    Z d   Z RS(   c         C   sE   t  i  t  i t  i t  i  } | i | d f  | |  _ |  _ d  S(   Ni    (   R4   t   AF_BLUETOOTHR
  t   BTPROTO_L2CAPR  R
  R
  (   R   t   peerR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   (  s    c         C   s   t  |  i i |   S(   N(   R  R
  RJ  (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  (  s    (   R   R   R   RJ  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  (  s   	t   BluetoothHCISocketc           B   s    e  Z d  d d  Z d   Z RS(   i   c      	   C   s   t  i  t  i t  i t  i  } | i t  i t  i d  | i t  i t  i d  | i t  i t  i t	 i
 d d d d d   | i | f  | |  _ |  _ d  S(   Ni   t   IIIh2xl    i    (   R4   R
  R
  t   BTPROTO_HCIR  t   SOL_HCIt   HCI_DATA_DIRt   HCI_TIME_STAMPt
   HCI_FILTERR   R   R  R
  R
  (   R   Rd  R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   (  s    .c         C   s   t  |  i i |   S(   N(   R  R
  RJ  (   R   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  (  s    N(   R   R   R   R   RJ  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  (  s   
c   &      C   s  t  | t  p t |  } n | d  j o t i } n t g  d  t _ t g  d  t _	 t
 g   t _ d } g  }	 g  }
 | D] } |
 | q ~
 } } t |  } h  } xI | D]A } | i   } | | j o | | i |  q | g | | <q W| d j  o | } | } n d } x"| d j od } | d j  o
 d  } n t i   \ } } t i |  } t i | d  } d } zt i   } | d j oLz t i i   | i   yc d } | o	 d GHn x2 | D]* } |  i |  | d 7} t i |  qW| o d | GHn WnY t j
 o nH t j
 o n6 t i d t i    t i d t i    n XWd  y` t i   g  } | D] } | i  o | | i  qq~ } t! i" t# | f |  | i   Wn n XXn| d j  o t i$ d	  nu| i   d } d  } | |  g } zyx| o& | t i   } | d j o Pqdn d  } t% p t& oR t' | g  g  d
  \ } } } t |  d j p |  | j o |  i(   } q nW t' | g  g  |  \ } } } t |  d j o Pn |  | j o |  i t)  } n | | j o/ | o t i   | } n | | i* |  =n | d  j o q7n d }  | i   } | | j o | | }! x t+ t |!   D] } | i, |! |  o |	 i |! | | f  | d j o t i- d d  n d }  | p |! | =| d 8} n0 t. |! | d  p | d 8} n d |! | _/ PqqWn | d j o | o Pn |  pM | d j o t i- d d  n | d 7} t i0 o t i i |  qq7q7Wn! t j
 o | o   qn XWd  y t! i1 |  \ }" } Wn' t2 j
 o t3 d t i    n8 Xt# i4 |"  x& t5 | |  D] \ } }# |# | _  qVWt i6 | d  XWd  | d j o t i7 d  n Xt8 t9 i: | i;   g   }$ | o t< d   |$  }$ n | o6 t |$  d j o# t |$  t |  j o
 | } n |$ } t |  d j o Pn | d 8} q#Wt i0 o' t |$ d  t _	 t
 |	  t _ n | o5 x2 |	 D]& \ }% } t. |% d  o
 |% `/ qqWn | o& d | t |	  t |	  | f GHn t
 |	  t |$ d  t i f S(   Nt
   Unansweredt   Senti    R   i   s   Begin emission:s   Finished to send %i packets.s   --- Error in child %is
   fork errorg?R|  R  R   s:   Child died unexpectedly. Packets may have not been sent %ic         S   s   t  |  d   S(   R  (   RM  (   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   o)  s    s:   
Received %i packets, got %i answers, remaining %i packets(=   R`   R!  R"  R   R   R  R%  RI  RJ  RK  R  RL  Rq   R  Rf   R   t   pipet   fdopent   forkR   R,  R~   R  R   Re  t
   SystemExitR  R   t	   exceptionR  Ru   t   setpgrpRL  R  R  Rr  R   R  t   DARWINR&   R
  R
  RS  R   R  R   RM  R  t   debug_matchR!  t   EOFErrorR   R@   t   zipt   waitpidt   _exitR  R   RD  RO  R"   (&   t   pksR   R  t   interR  R  R>  R  t   nbrecvt   ansR  Rc   t   all_stimulit   tobesentt   notanst   hsentR   R  t   autostopR  t   rdpipet   wrpipeR  RJ  t
   sent_timest   stoptimet
   remaintimet   inmaskRg   t   inpt   outR  R  t   hlstt   acRT  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   sndrcv(  s,   % 


	 

2	
	 
 

 3

 &c   
      O   s  t  | t  p t |  } n | d  j o t i } n d } | d  j	 o | } n | p
 d } n y~ xw | oo xM | D]E }	 |  i |	  | d 7} | o t i d d  n t	 i
 |  q} W| d j  o | d 7} qo qo WWn t j
 o n X|  i   | o d | GHn d  S(   Ni    ii   R   s   
Sent %i packets.(   R`   R!  R"  R   R   R  R  R   R   R   Re  R  R~   (
   R   R6   R
  R  R  R  R\   RA   R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   __gen_send)  s2    

 

c         O   s5   t  t i | |   |  d | d | d | d | d S(   sW   Send packets at layer 3
send(packets, [inter=0], [loop=0], [verbose=conf.verb]) -> NoneR
  R  R  R  N(   R  R   t   L3socket(   R6   R
  R  R  R  R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  )  s    c   	      O   so   | d j o' | d j	 o t i i |  d } n t t i d | | |  |  d | d | d | d | d S(   sX   Send packets at layer 2
sendp(packets, [inter=0], [loop=0], [verbose=conf.verb]) -> Nonei    Rd  R
  R  R  R  N(   R   R   Rf  R  t   L2socket(	   R6   R
  R  Rd  t
   iface_hintR  R  R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   sendp)  s    c         C   sD  | d	 j o t i } n d | g } | d	 j	 o | i d |  nR | d	 j	 o | i d |  n0 | d	 j	 o | i d |  n | i d  | o | i d |  n t i d  } | i |  t | |   zP y) t i t i t i	 i
 t i	 i
 |  Wn  t j
 o t i d  n XWd	 t i |  Xd	 S(
   s  Send packets at layer 2 using tcpreplay for performance
    pps:  packets per second
    mpbs: MBits per second
    realtime: use packet's timestamp, bending time with realtime value
    loop: number of times to process the packet list
    iface: output interface s
   --intf1=%ss   --pps=%is	   --mbps=%is   --multiplier=%is
   --topspeeds	   --loop=%iR#   s   Interrupted by userN(   R   R   Rd  Rf   R   R*   t   wrpcapt   spawnlpt   P_WAITR   t	   tcpreplayR  R  Ru   t   unlink(   R6   t   ppst   mbpst   realtimeR  Rd  R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   sendpfast)  s*    )c   
      O   sn   | i  d  p d | d <n t i d | d | d |  } t | |  | |  \ } } }	 | i   | | f S(   s  Send and receive packets at layer 3
nofilter: put 1 to avoid use of bpf filters
retry:    if positive, how many times to resend unanswered packets
          if negative, how many times to retry when no more packets are answered
timeout:  how much time to wait after the last packet has been sent
verbose:  set verbosity level
multi:    whether to accept multiple answers for the same stimulus
filter:   provide a BPF filter
iface:    listen answers only on the given interfaceR  iR"   Rd  R  (   R  R   R  R  R~   (
   R6   R"   Rd  R  R\   RA   R   R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  )  s    

c   
      O   s   | i  d  p d | d <n t i d | d | d |  } t | |  | |  \ } } }	 | i   t |  d j o | d d Sn d Sd S(	   s  Send packets at layer 3 and return only the first answer
nofilter: put 1 to avoid use of bpf filters
retry:    if positive, how many times to resend unanswered packets
          if negative, how many times to retry when no more packets are answered
timeout:  how much time to wait after the last packet has been sent
verbose:  set verbosity level
multi:    whether to accept multiple answers for the same stimulus
filter:   provide a BPF filter
iface:    listen answers only on the given interfaceR  iR"   R  Rd  i    i   N(   R  R   R  R  R~   Rq   R   (
   R6   R"   Rd  R  R\   RA   R   R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   sr1)  s    

c      	   O   s   | i  d  p d | d <n | d j o' | d j	 o t i i |  d } n t i d | d | d | d |  } t | |  | |  \ }	 }
 } | i   |	 |
 f S(	   s  Send and receive packets at layer 2
nofilter: put 1 to avoid use of bpf filters
retry:    if positive, how many times to resend unanswered packets
          if negative, how many times to retry when no more packets are answered
timeout:  how much time to wait after the last packet has been sent
verbose:  set verbosity level
multi:    whether to accept multiple answers for the same stimulus
filter:   provide a BPF filter
iface:    work only on the given interfaceR  ii    Rd  R"   R  R   N(   R  R   R   Rf  R  R  R~   (   R6   Rd  R  R"   R  R   R\   RA   R   R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   srp)  s    
$
c          O   s^   | i  d  p d | d <n t |  |   \ } } t |  d j o | d d Sn d Sd S(   s  Send and receive packets at layer 2 and return only the first answer
nofilter: put 1 to avoid use of bpf filters
retry:    if positive, how many times to resend unanswered packets
          if negative, how many times to retry when no more packets are answered
timeout:  how much time to wait after the last packet has been sent
verbose:  set verbosity level
multi:    whether to accept multiple answers for the same stimulus
filter:   provide a BPF filter
iface:    work only on the given interfaceR  ii    i   N(   R  R   Rq   R   (   R\   RA   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  *  s    
c         C   s   |  d  i    S(   i   (   R7  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   *  s    c         C   s
   |  i    S(    (   R7  (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   *  s    c	         O   s6  d } d } t  i } | d  j o t  i } n d } g  } g  } | d  j o t d | d  } n yjxc| d N} | i | i g | } | d  j	 o  | d j o Pn | d 8} n t i   } d G|  | d | d d d d |	 |
 } | t | d  t | d  7} | t | d  7} | d j o{ | ot t | d  d j o] d	 t | d  } d
 | i	 |  Gx5 | d D]% } | | |   GHd t |  Gq}Wn | d j o{ | ot t | d  d j o] d t | d  } d
 | i
 |  Gx5 | d D]% } | | |   GHd t |  GqWn | d j o/ | p | o  d t t t | d    GHn | o  | | d 7} | | d 7} n t i   } | | | j  o t i | | |  qk qk Wn t j
 o n X| o4 | d j o' | i d | | d | | f  GHn t |  t |  f S(   Ni    i   i   i   s	   send...R  R  R  s   RECV %i:s   RT   s   fail %i:s   recv:%i  fail:%is4   
Sent %i packets, received %i packets. %3.1f%% hits.g      Y@(   R   R   R   R  R   t   event   oddR   Rq   R[  t   failRo   RN   Re  R  t   normalR  R%  (   t   srfunct   pktsRE  t   prnfailR
  R  R  R  t   storeR\   RA   R   Rg   R  t   parityR   t   unansR   R   R  R   Rc   RW  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   __sr_loop*  sd    	
$"+ +   'c         O   s   t  t |  | |  S(   ss   Send a packet at layer 3 in loop and print the answer each time
srloop(pkts, [prn], [inter], [count], ...) --> None(   R+  R  (   R&  R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   srloopP*  s    c         O   s   t  t |  | |  S(   ss   Send a packet at layer 2 in loop and print the answer each time
srloop(pkts, [prn], [inter], [count], ...) --> None(   R+  R   (   R&  R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   srploopU*  s    c         C   s   |  \ } } | i    S(    (   R7  (   RI   R   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   [*  s    c         C   s-  t  | t  p t |  } n g  } | D] } | | q+ ~ } t   }	 h  }
 h  } xI | D]A } | i   } | | j o | | i |  q] | g | | <q] Wd   } | |  } |  i   } } y>x7t | g | g g   \ } } } | | j o |  i | i	    n | | j o |  i
 t  } | d  j o q n | i   } | | j o | | } x | D] } | i |  os | | | f  } | o" | |
 j o qln d  |
 | <n | d  j	 o	 | GHn | o |	 i | | f  qqlqlWqq q Wn! t j
 o | o   q)n X|	 S(   Nc         s   s    x x |  D] } | Vq
 Wq d  S(   N(    (   R  Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   send_in_loopj*  s     (   R`   R!  R"  R  R  Rf   R
  R&   R  R   RJ  R
  R   R  R  (   R
  R   RE  R  R(  t   uniqueR  Rc   R  t   receivedt   seenR  R   R  R.  t   packets_to_sendt   ssockt   rsockt   readyrt   readysRL   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   sndrcvflood[*  sV    !	 	!
 	.c         O   sA   t  i d | d | d |  } t | |  | |  } | i   | S(   sX  Flood and receive packets at layer 3
prn:      function applied to packets received. Ret val is printed if not None
store:    if 1 (default), store answers and return them
unique:   only consider packets whose print 
nofilter: put 1 to avoid use of bpf filters
filter:   provide a BPF filter
iface:    listen answers only on the given interfaceR"   Rd  R  (   R   R  R7  R~   (   R6   R"   Rd  R  R\   RA   R   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   srflood*  s    
c   	      O   su   | d j o' | d j	 o t i i |  d } n t i d | d | d |  } t | |  | |  } | i   | S(   sX  Flood and receive packets at layer 2
prn:      function applied to packets received. Ret val is printed if not None
store:    if 1 (default), store answers and return them
unique:   only consider packets whose print 
nofilter: put 1 to avoid use of bpf filters
filter:   provide a BPF filter
iface:    listen answers only on the given interfacei    R"   Rd  R  N(   R   R   Rf  R  R7  R~   (	   R6   R"   Rd  R  R  R\   RA   R   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   srpflood*  s    
g?c   	      O   sJ   t  i d |   } t | | d | | | \ } } } | i   | | f S(   NR
  R
  (   R   t   BTsocketR  R~   (	   R
  R&  R
  R\   RA   R   R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   srbt*  s    $
c         O   sB   t  |  | | |  \ } } t |  d j o | d d Sn d  S(   Ni    i   (   R;  Rq   (   R
  R&  R\   RA   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   srbt1*  s    c         O   s   t  |  | |  i |  d S(   s   Write a list of packets to a pcap file
gz: set to 1 to save a gzipped capture
linktype: force linktype value
endianness: "<" or ">", force endiannessN(   t
   PcapWriterR   (   Rw   R   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  *  s    c         C   s   t  |   i d |  S(   sJ   Read a pcap file and return a packet list
count: read only <count> packetsR  (   t
   PcapReadert   read_all(   Rw   R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   rdpcap*  s    R>  c           B   sY   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z	 d	   Z
 RS(
   s   A stateful pcap reader
    
    Based entirely on scapy.rdpcap(), this class allows for packets
    to be dispatched without having to be loaded into memory all at
    once
    c   
   	   C   sI  | |  _  y+ t i | d  |  _ |  i i d  } Wn7 t j
 o+ t | d  |  _ |  i i d  } n X| d j o d |  _ n$ | d j o d |  _ n
 t d  |  i i d  } t |  d j  o t d	  n t	 i
 |  i d
 |  \ } } } } } }	 t i |	 t  |  _ |  i t j o t d |	 |	 f  n d  S(   NR   i   s   R   s   òR   s#   Not a pcap capture file (bad magic)i   s   Invalid pcap file (too short)t   HHIIIIs:   PcapReader: unkonwon LL type [%i]/[%#x]. Using Raw packets(   Rw   R  Rl   R   R-  Rv   t   endiant   RuntimeWarningRq   R   R   R
  R   RV  t   LLclsR   (
   R   Rw   R  t   hdrt   vermajt   vermint   tzt   sigt   snaplent   linktype(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   *  s&    		+c         C   s   |  S(   N(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRP   *  s    c         C   s'   |  i    } | d j o
 t  n | S(   sS   impliment the iterator protocol on a set of packets in a
        pcap file
        N(   t   read_packetR   R.  (   R   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   *  s    
c         C   s   |  i  i d  } t |  d j  o d Sn t i |  i d |  \ } } } } |  i  i |  } y |  i |  } Wn9 t j
 o
   n% t	 i
 o   n t |  } n X| d | | _ | S(   ss   return a single packet read from the file
        
        returns None when no more packets are available
        i   t   IIIIgư>N(   R   R-  Rq   R   R   R   RB  RD  R  R   R  RV  R   (   R   RE  R  t   usect   caplenR  R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRL  *  s    %
c         C   s;   |  i    } x( | d j o | |  |  i    } q Wd S(   s   call the specified callback routine for each packet read
        
        This is just a convienience function for the main loop
        that allows for easy launching of packet processing in a 
        thread.
        N(   RL  R   (   R   t   callbackRc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   dispatch+  s    
ic         C   so   g  } xG | d j o9 | d 8} |  i    } | d j o Pn | i |  q	 Wt | d t i i |  i  S(   s6   return a list of all packets in the pcap file
        i    i   R  N(   RL  R   Rf   R%  R   Ra   R9  Rw   (   R   R  R  Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR?  +  s    
c         C   s
   |  i    S(   s    Emulate a socket
        (   RL  (   R   R:  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRJ  '+  s    c         C   s   |  i  i   S(   N(   R   R
  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  ,+  s    (   R   R   RW  R   RP   R   RL  RQ  R?  RJ  R
  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR>  *  s   			
			R=  c           B   s\   e  Z d  Z d	 e d e e d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(
   s4   A stream PCAP writer with more control than wrpcap()R   c         C   s   | |  _  d |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d } | o
 d } n t t i g | | | o d p d | o d p |  |  _	 d S(   s  
        linktype: force linktype to a given value. If None, linktype is taken
                  from the first writter packet
        gz: compress the capture on the fly
        endianness: force an endianness (little:"<", big:">"). Default is native
        append: append packets to the capture file instead of truncating it
        sync: do not bufferize writes to the capture file
        i    i   t   abR  i	   N(
   RK  t   header_presentRf   t   gzRB  Rw   R  Rl   R  R   (   R   Rw   RK  RT  t
   endiannessRf   R  t   bufsz(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   3+  s    
							
c         C   s   |  i  i   S(   N(   R   R
  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR
  L+  s    c      
   C   s   d |  _  |  i d  j oP t |  t j p t |  t j o | d } n t i | i d  |  _ n |  i	 o> t
 t i
 g |  i |  i d  } | i d  o d  Sq n |  i i t i |  i d d d d d d t |  i   |  i i   d  S(	   Ni   i    R   i   t   IHHIIIIl   CeC i   i   (   RS  RK  R   R   R   Ro   t
   LLNumTypesR   R   Rf   Rl   R  RT  Rw   R-  R   R   R   R   RB  R
  t   flush(   R   R   RO  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   _write_headerO+  s    	&
"c         C   s=   |  i  p |  i |  n x | D] } |  i |  q" Wd S(   sd   accepts a either a single packet or a list of packets
        to be written to the dumpfile
        N(   RS  RZ  t   _write_packet(   R   R   Rc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   e+  s
    
 c         C   s   t  |  } t |  } t | i  } t | i | d  } |  i i t i |  i d | | | |   |  i i |  |  i	 o |  i
 o |  i i   n d S(   s0   writes a single packet to the pcap file
        i@B RM  N(   R   Rq   Rr   R   R   R   R   R   RB  RT  R  RY  (   R   t   packetR   R   R  RN  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR[  n+  s    ,c         C   s   |  i  i   S(   N(   R   RY  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRY  z+  s    c         C   s   |  i  i   S(   N(   R   R~   (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR~   |+  s    N(   R   R   RW  R   RZ   R   R
  RZ  R   R[  RY  R~   (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR=  1+  s   						sh   ^(0x[0-9a-fA-F]{2,}[ :	]|(0x)?[0-9a-fA-F]{2,}:|(0x)?[0-9a-fA-F]{3,}[: 	]|) *(([0-9a-fA-F]{2} {,2}){,16})c          C   s   d }  yQ xJ t    i   } y! |  t i |  i   d 7}  Wq t d  q q Xq Wn t j
 o n X|  i d d  }  d } xJ t t	 |   d  D]2 } | t
 t |  d | d | d !d   7} q W| S(   NR   i   s   Parsing error during hexcapRT   i   i   (   t	   raw_inputRn   t   re_extract_hexcapRL  R  R   R
  R  R   Rq   R   Rr   (   Rc   R   t   p2R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRE  +  s"    !
 0c         C   sH   t  i d  } t | |   t  i t  i t i i t i i d |  d  S(   NR#   s   -r(   R   R*   R  R  t   P_NOWAITR   R   t	   wireshark(   t   pktlistR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRa  +  s    c         C   sy   t  |   }  t i d  } t | d  i |   t i t i t i i	 t i i	 |  t |  i
   }  t i |  |  S(   NR#   R   (   R   R   R*   Rl   R   R  R  R   R   t   hexeditR-  R  (   R6   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRc  +  s    %t   KnowledgeBasec           B   s/   e  Z d    Z d   Z d d  Z d   Z RS(   c         C   s   | |  _  d  |  _ d  S(   N(   Rw   R   R_  (   R   Rw   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   +  s    	c         C   s   d |  _  d  S(   NR   (   R_  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   lazy_init+  s    c         C   sW   | d  j	 o | |  _ n |  i } d  |  _ |  i   |  i d  j o | |  _ n d  S(   N(   R   Rw   R_  Re  (   R   Rw   t   oldbase(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   reload+  s    		
c         C   s%   |  i  d  j o |  i   n |  i  S(   N(   R_  R   Re  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   get_base+  s    N(   R   R   R   Re  R   Rg  Rh  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRd  +  s   			t   IPCountryKnowledgeBasec           B   s   e  Z d  Z d   Z RS(   s   
How to generate the base :
db = []
for l in open("GeoIPCountryWhois.csv").readlines():
    s,e,c = l.split(",")[2:5]
    db.append((int(s[1:-1]),int(e[1:-1]),c[1:-1]))
cPickle.dump(gzip.open("xxx","w"),db)
c         C   s   t  |  i  |  _ d  S(   N(   R3  Rw   R_  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRe  +  s    (   R   R   RW  Re  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRi  +  s   t   CountryLocKnowledgeBasec           B   s   e  Z d    Z RS(   c         C   s   t  |  i  } h  |  _ xx | i   } | p Pn | i   i d  } t |  d j o q n | \ } } } t |  t |  f |  i | <q | i   d  S(   NR&  i   (	   Rl   Rw   R_  R  Rn   Rp   Rq   Rg  R~   (   R   R   R   R   t   latR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRe  +  s    	"(   R   R   Re  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRj  +  s   c   	      C   s  t  t |  i d   }  |  d |  d d >|  d d >|  d d >}  t i   } t i   } d } t |  d } xI | | d j o7 | | d } |  | | d j o
 | } qw | } qw W| | \ } } } | |  j o! |  | j o | i | d   Sn d  S(	   NR   i   i   l    i   l    i    l    (	   RN   Rr   Rp   t   country_loc_kdbRh  t   IP_country_kdbRq   R   R   (	   R   t   cloct   dbR   R   t   guessR   R|   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  +  s    .
t   p0fKnowledgeBasec           B   s   e  Z d    Z d   Z RS(   c         C   s   t  i |  |  d  S(   N(   Rd  R   (   R   Rw   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR   ,  s    c         C   s0  y t  |  i  } Wn( t j
 o t d |  i  d  Sn Xy g  |  _ x | D] } | d d j o qQ n t | i d   } t |  d j  o qQ n t t	 | d d ! } |  i i
 | d | d | d | d	 | d | d
 | d | d d  f  qQ WWn t d  d  |  _ n X| i   d  S(   Ns   Can't open base %si    Ri   s   
R   i   i   i   i   i   i   i   is,   Can't parse p0f database (new p0f version ?)(   Ri   s   
(   Rl   Rw   Rv   R   R_  Ro   Rp   Rq   RN   Rr   Rf   R   R~   (   R   R   R   t   li(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRe  ,  s(    		 T
(   R   R   R   Re  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRq  ,  s   	c      	   C   s  xU |  i  t  oD |  i  t  o4 |  i t  }  t |  i t  o Pn |  i }  q Wt |  t  p t |  i t  o t d   n |  i i d @d j o t d   n |  i } |  i d @d } t	 |   } | d j o
 d } n d } d } t
 } t
 } |  t i d >d	 } x|  i i D]}	 | d
 8} |	 d d j o4 | d t |	 d
  d 7} |	 d
 } | d 8} q+|	 d d j o* | d t |	 d
  d 7} | d 8} q+|	 d d j oZ |	 d
 d d j o | d 7} n | d 7} |	 d
 d
 d j o
 t } n | d 8} q+|	 d d j o | d 7} | d
 8} q+|	 d d j o | d 7} q+|	 d d j o% | d 7} | d j o
 t } qq+| d 7} q+W| d  } | d j o
 d } n |  i i }
 | d j oj |
 | d j o d t |
 |  }
 n2 |
 | d d j o d t |
 | d  }
 n t |
  }
 n d } | o | d  7} n |  t i d j o | d! 7} n |  t i d j o | d" 7} n |  t i d j o | d# 7} n |  t i d j o | d$ 7} n |  t i d j o | d% 7} n | o | d 7} n |  t i d @d j o | d& 7} n t |  t i t  p | d' 7} n | d j o
 d } n |
 | | | | | f S((   Ns   Not a TCP/IP packeti   i   s   Not a syn packetid   i    R   ii   i   R  Re  R&  i   R  t   WRs  s   T0,s   T,i	   R  s   S,R  s   N,R  s   E,s   ?,R   t   Si(   t   Tt   Pt   ZR  t   Ut   XR  t   Ft   D(   R<  R\  R0  RW  R`   R  R4  R  RQ  Rq   RZ   R  R   R   R[   Ro  R  Rp  Rm  Rl  RR  (   R   RQ  t   dft   sst   ooot   msst   qqTt   qqPt   ilent   optiont   wint   qq(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   packet2p0f,,  s    #%	
 







c      	   C   ss  d } | |  d | d j p] | d d j pL | d d d j o7 |  d i    o& t |  d  t | d d  d j 7} | | d |  d j o | d |  d d j  7} x/ d d d g D] } | |  | | | j 7} q W|  d	 i d
  } | d	 i d
  } t |  t |  j oOt } x't t |   D]} | | | | j p t | |  d j oI t | |  d j o2 | | d d j o | | d | | d j p t | |  d j os t | |  d j o\ | | d d j oG | | d | | d j o* t | | d  t | | d  d j p t } Pq9q9W| o | t |  7} qon | S(   Ni    R|  R   i   i    i   i   i   i   R&  (   t   isdigitRr   Rp   Rq   R[   R   RZ   (   R6   RJ   R   R   t   xoptt   yoptt   same(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   p0f_correl,  s.    x1  .2.2-	c         C   s   t  i   } | p t d  g  Sn t | d d  } g  } t |   } t | d i d   d } x[ | D]S } t | |  } | | j o1 | i | d | d | d |  t i	 f  qo qo W| S(	   sf   Passive OS fingerprinting: which OS emitted this TCP SYN ?
p0f(packet) -> accuracy, [list of guesses]
s   p0f base empty.i    i   R&  i   i   i   i   (
   t   p0f_kdbRh  R   Rq   R  Rp   R  Rf   R\  RQ  (   R   t   pbR   Rg   RI  R  R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   p0f,  s    
 5c         C   sE  y t  |   } Wn d  Sn X| g  j o3 d d d i t t t |     d d  f } n | d } d  } y t |   } Wn n X| d j o
 d  } n |  i d | d d | d  } | d  j	 o) | |  i d	 t | d
  d  7} n | |  i d  7} | d d  j	 o  | d t | d  d 7} n | GHd  S(   Nt   UNKNOWNt   [R   s   :?:?]i    s   %IP.src%:%TCP.sport% - RT   i   s    (up: i  s    hrs)
  -> %IP.dst%:%TCP.dport%s   
  -> %IP.dst%:%TCP.dport%i   s    (distance R  (   R  RU   RN   R   R  R   t
   pkt2uptimeRU  (   R   Rg   t   uptimeR  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   prnp0f,  s*    3

#) id   c         C   s   t  |  t  p t d   n t  |  t  o t d   n t  |  t  p t |  i  Sn x< |  i D]1 } | d d j o | d d | } | Sqk qk Wt d   d S(   sl   Calculate the date the machine which emitted the packet booted using TCP timestamp
pkt2uptime(pkt, [HZ=100])s   Not a TCP packeti    Rs  i   s   No timestamp optionN(   R`   R(  R4  RR  R0  R  R  R   (   R   t   HZR  RT  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ,  s    
 c         C   sQ   |  d j o d Sn d } d } x% |  D] } | d | i  |  O} q( Wd | S(   NR~  t   FSRPAUXYi    i   s   %x(   RS  (   R  t   flvR
  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   quesoTCPflags,  s     t   QuesoKnowledgeBasec           B   s   e  Z d    Z RS(   c         C   s  y t  |  i  } Wn t j
 o d  Sn Xh  |  _ d  } y!x | D] } | i   } | p | d d j o qF n | d d j o; | d  j	 o | | d <n | d i   } |  i } qF n | d t d  j o qF n | d i   } t | d  | d <d	 i	 |  } | i
 |  p h  | | <n | | } qF W| d  j	 o | | d <n Wn  d  |  _ t d
 |  i  n X| i   d  S(   Ni    t   ;R|  R   i   t   0123456i   iRT   s   Can't load queso base [%s](   Rl   Rw   Rv   R_  R   Rn   R   Rp   R  RU   R  R   R~   (   R   R   Rc   R   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRe  ,  s@    		 		(   R   R   Re  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  ,  s   iP   c      
   C   sJ  t  i   } g  } x1d d d d d d d g D]} t t d |   t d	 | d
 | d t    d | d d \ } } t |  d j o
 d } n | d \ }	 }
 d |
 i d j } |
 i p |
 d 7}
 nB |
 i |	 i d j o | d d 7} n | d |
 i |	 i 7} | d |
 i	 7} | d |
 i
 i 7} | i |  q. W| S(   NRt  R  Rz  t   FAt   SFRv  t   SECR  Ra  R  R  R  R  i    s   - - - -s   %is    0i  s    Rs    +%is    %Xs    %x(   t	   queso_kdbRh  R  R\  R0  R/  Rq   R  Rl  Ro  R  R  Rf   (   R   Ra  R  Rc   R  R  R   R*  t   rsR   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt	   queso_sig"-  s&     .

c         C   s   t  i   } |  i   g  } yN xG |  o? |  i   } | | } | i d  o | i | d  q" q" WWn t j
 o n X| S(   NR   (   R  Rh  R  R  R  Rf   R  (   RI  Rc   R  R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   queso_search8-  s    


c          O   s   t  t |  |    S(   s:   Queso OS fingerprinting
queso(target, dport=80, timeout=3)(   R  R  (   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   quesoG-  s    t   NmapKnowledgeBasec           B   s   e  Z d    Z RS(   c         C   s  y t  |  i  } Wn t j
 o d  Sn Xg  |  _ d  } yxZ| D]R} | i   } | p | d d j o qF n | d  d j oM | d  j	 o |  i i | | f  n | d i   } h  } |  i } qF n | d  d j o qF n | i d  } | i d  } | d j  p | d j  o t d	  qF n | |  } t	 d
   | | d | !i
 d   }	 h  }
 x |	 D] \ } } | |
 | <qtW|
 | | <qF W| d  j	 o |  i i | | f  n Wn! d  |  _ t d |  i  n X| i   d  S(   Ni    Ri   i   s   Fingerprint i   s   Class R  R  s"   error reading nmap os fp base filec         S   s   |  i  d   S(   Rg  (   Rp   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   p-  s    i   R   s1   Can't read nmap database [%s](new nmap version ?)(   Rl   Rw   Rv   R_  R   Rn   Rf   Rm   R   RN   Rp   R~   (   R   R   R  R   RI  Rc   R  R   t   testR   t   siR   R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRe  T-  sN    		 	

& 	(   R   R   Re  (    (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyR  S-  s   c         C   sT   d } d } xA t  t |   D]- } |  d @o | | | } n |  d L}  q W| S(   NRn  R   i   (   R   Rq   (   R   t   flR   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   TCPflags2str|-  s     c         C   s   h  } |  d  j	 o |  i d @o d p d | d <d |  i | d <|  i d j o d p |  i d j o d	 p d
 | d <t |  i i  | d <d i t d   |  i i   | d <n d | d <| S(   Ni   t   Yt   NR_  s   %XRs  s   S++i   Rt  t   OR
  R  R   c         S   s   |  d  d  S(   i    (    (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   -  s    t   Opst   Resp(	   R   R  Ro  Rl  R  R  RU   RN   R   (   R   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_tcppacket_sig-  s    8)
c         C   s  h  } | d  j o d | d <n| i d @o d p d | d <d | i | d <d | i | d <d | i i i | d	 <|  i | i i i j o d
 p d | d <|  i | i t  i j o d
 p$ | i t  i d j o d p d | d <|  i i | i t	  i j o d
 p$ | i t	  i d j o d p d | d <d | i t	  i | d <| i t
  d  j o d
 p0 |  i t
  i | i t
  i j o d
 p d | d <| S(   NR  R  i   R  R_  s   %Xt   TOSt   IPLENt   RIPTLt   ERz  t   RIDi    R}  t   RIPCKt   UCKt   ULENt   DAT(   R   R  R]  Rq   R  R  Rb  RW  R  R  RV  R!  (   Rt  Ru  Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_udppacket_sig-  s    *MPSc         C   s   d } xT |  i    D]F } | i |  o0 |  | | | i d  j o | d 7} qY q q W| d j o |  i d  d j o d Sn d | t |  i     Sd  S(   Ni    R   i   R  R  gffffff?g      ?(   RQ   R  Rp   R   Rq   (   R1  R  R   RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_match_one_sig-  s     #c         C   s  h  } d' d( d) d d* f g } t d	 |  d
 d  t d d d d d | d | d d  t d	 |  d
 d  t d d d d d | d | d d  t d	 |  d
 d  t d d d d d | d | d d  t d	 |  d
 d  t d d d d d | d | d d  t d	 |  d
 d  t d d d d d | d | d d  t d	 |  d
 d  t d d d d d | d | d d  t d	 |  d
 d  t d d d d d | d | d d  t t t d	 |   t d d d |  d d   g } t | d  d! \ } } | t d"   |  7} x | D] \ }	 }
 |	 i d j o t |	 |
  | d# <qd$ |	 i d% } |
 d  j	 o( |
 i	 t
  o t d& |  d  }
 n t |
  | | <qW| S(+   NR  i
   R  R  i   Rs  i{   i    R  R  i   R  Rk  i  Ra  R   R  R  i  i  t   SFUPi  R  i  Rt  i  i  t   FPUi  i,  R   R  i   c         S   s
   |  d  f S(   N(   R   (   R6   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   -  s    t   PUs   T%ii  s   Test %s answered by an ICMP(   s   WScalei
   (   s   NOPN(   s   MSSi   (   i{   i    (   R   R\  R0  R   R1  R  RN   Rk  R  R<  R2  R   R  (   R   t   oportt   cportt   ucportR  t   tcpoptt   testsR   R*  Rt  Ru  RT  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_sig-  s2    77777779 
c         C   sg   |  i    }  h  } d |  j o t |  d   | d <|  d =n x" |  D] } t |  |  | | <qE W| S(   NR  (   R  R  R  (   R  R  RR   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_probes2sig-  s     c         C   s   d g  f } x t  i   D] \ } } d } x@ |  i   D]2 } | | j o | t |  | | |  7} q8 q8 W| t |  i    :} | | d j o | | g f } q | | d j o | d i |  q q W| S(   Ni    g        i   (   t   nmap_kdbRh  RQ   R  Rq   Rf   (   t   sigsRp  R   t   fpR   RT  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_search-  s      #c         C   s   t  |  | |  } t |  S(   sc   nmap fingerprinting
nmap_fp(target, [oport=80,] [cport=81,]) -> list of best guesses with accuracy
(   R  R  (   R   R  R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_fp-  s    c   
      C   sM  d d d d d d d d d	 g	 } d
 d d d d d d d d d d d d d d d d d d g } g  } x2 |  i    D]$ } | | j o | i |  qs qs Wx | D] } |  i |  } | d  j o q n g  } xH | D]@ } | i |  }	 |	 d  j o q n | i d | |	 f  q W| i d | d i |  f  q Wd  i |  S(!   Nt   TSeqt   T1t   T2t   T3t   T4t   T5t   T6t   T7R  t   Classt   gcdt   SIt   IPIDt   TSR  R_  Rs  R
  R  R  R  R  R  R  R  R  R  R  s   %s=%ss   %s(%s)R   s   
(   RQ   Rf   R   R   RU   (
   RI  t   tordert   korderR  R   RT  Ri  R   RR   R
  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   nmap_sig2txt-  s.    !   $c         O   s  d }	 | d j o3 | d j o t i } n | d t | |  }
 n t |  }
 g  } | d j	 o t i   | } n d } x)y| d j	 o& | t i   } | d j o Pq n t |
 g g  g  |  } |
 | d j o |
 i t  } | d j o Pn | o | |  o w n | o | i	 |  n |	 d 7}	 | o& | |  } | d j	 o	 | GHqmn |  d j o |	 |  j o Pqn Wq t
 j
 o Pq Xq |
 i   t | d  S(   s  Sniff packets
sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets

  count: number of packets to capture. 0 means infinity
  store: wether to store sniffed packets or discard them
    prn: function to apply to each packet. If something is returned,
         it is displayed. Ex:
         ex: prn = lambda x: x.summary()
lfilter: python function applied to each packet to determine
         if further action may be done
         ex: lfilter = lambda x: x.haslayer(Padding)
offline: pcap file to read packets from, instead of sniffing them
timeout: stop sniffing after a given time (default: None)
L2socket: use the provided L2socket
    i    R   i   t   SniffedN(   R   R   t   L2listenR
  R>  R   R&   RJ  R
  Rf   R  R~   R%  (   R  R(  t   offlineRE  RF  R  R  t   argt   kargR   R   R  R	  R  t   selRc   Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   sniff.  sH    	
	
c         C   s   t  |   } t d |  t d d d | d |   } yK xD t | d |  t i d j o t i d d  n t i	 |  q: Wn t
 j
 o n Xd	 S(
   so   Poison target's cache with (your MAC,victim's IP) couple
arpcachepoison(target, victim, [interval=60]) -> None
R  R  s   who-hasRY  R  R  i   R   N(   R  R  R  R  R   R  R   R   R   Re  R  (   R   t   victimt   intervalt   tmacRc   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   arpcachepoisonL.  s    (i   c	      	   K   s   | d j o t i } n | d j o
 d } n | d j oe t t d |  d t   d | | f  t d t   d | d |  d | d	 | d
 | |	 \ }
 } nP d } t t d |  d t   d | | f  | d | d	 | d
 | |	 \ }
 } t |
 i	  }
 | o |
 i
   n |
 | f S(   sl   Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None
sq   (icmp and (icmp[0]=3 or icmp[0]=4 or icmp[0]=5 or icmp[0]=11 or icmp[0]=12)) or (tcp and (tcp[13] & 0x16 > 0x10))R  R  RQ  R  Rk  Ra  R  R"   R  R   N(   R   R   R  R  R\  R.  R0  R/  R  R  R  (   R   Ra  t   minttlt   maxttlRk  t   l4R"   R  R  RA   R  R  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   traceroute[.  s    
C"+c         K   s   | d
 j o t i } n t t d d  t d |   d | d d d | d |  | \ } } t | i  } | oF | d
 j	 o9 x6 | D]* } | d	 i t	 i	   f t
 | d	 i <q Wn | o | i   n | | f S(   s   Send ARP who-has requests to determine which hosts are up
arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None
Set cache=True if you want arping to modify internal ARP-CacheR  s   ff:ff:ff:ff:ff:ffR  R  R"   s   arp and arp[7] = 2R  R  i   N(   R   R   R  R   R  R  R  R  R  R   Rr  RY  R  (   Ra  R  R\  R  RA   R   R*  t   pair(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   arpingw.  s    % ,c         C   s   | | i  d  d } t t d |   t   t d d d t d | d d	  g d
 t d | d d d | d |  g  d d d d } | o$ | i t  o | i t  i	 Sn d Sd S(   s   Send a DNS add message to a nameserver for "name" to have a new "rdata"
dyndns_add(nameserver, name, rdata, type="A", ttl=10) -> result code (0=ok)

example: dyndns_add("ns1.toto.com", "dyn.toto.com", "127.0.0.1")
RFC2136
R   i   R  R  i   R  R  R  R  R  R  R   R  RQ  R   R  i    R  iN(
   Rm   R  R\  R1  R  R  R  R<  RW  R  (   t
   nameserverR  R   R   RQ  t   zoneRg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   dyndns_add.  s    "c         C   s   | | i  d  d } t t d |   t   t d d d t d | d d	  g d
 t d | d | d d d d d d  g  d d d d } | o$ | i t  o | i t  i	 Sn d Sd S(   s   Send a DNS delete message to a nameserver for "name"
dyndns_del(nameserver, name, type="ANY", ttl=10) -> result code (0=ok)

example: dyndns_del("ns1.toto.com", "dyn.toto.com")
RFC2136
R   i   R  R  i   R  R  R  R  R  R  R   R  R  RQ  i    R   R   R  R  iN(
   Rm   R  R\  R1  R  R  R  R<  RW  R  (   R  R  R   RQ  R  Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   dyndns_del.  s    "s   ff:ff:00:00:00:00c         K   sM   t  t d |  t d d d |   d t d |  d d d	 d
 | } | d j	 S(   sL   Try to guess if target is in Promisc mode. The target is provided by its ip.R  R  s   who-hasR  R   R  R  i   R  i    N(   R  R  R  R   R   (   R   t
   fake_bcastRA   t	   responses(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt
   is_promisc.  s    Cs   ff:ff:ff:ff:ff:fec      	   K   sf   t  t d |  t d |   d d d | d |  | \ } } t | i d d } | i   | | f S(	   sq   Send ARP who-has requests to determine which hosts are in promiscuous mode
    promiscping(net, iface=conf.iface)R  R  R"   s   arp and arp[7] = 2R  R  R  t   PROMISCPing(   R   R  R  R  R  R   (   Ra  R  R  RA   R   R*  (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   promiscping.  s
    
c         C   sC   t  t d |   t   t d t d  d d  t d t     S(   NR  R  i   R  i   R  (   R  R\  R1  R  R7  R  R
  (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   ikescan.  s    c         K   s   t  i d j o t d  n |  d  j o t  i }  n t |   \ } } t t d d  t d d d d  t	 d d	 d
 d  t
 d |  t d d d g  d |  | S(   Ni    s@   conf.checkIPaddr is not 0, I may not be able to match the answerR  s   ff:ff:ff:ff:ff:ffRO  s   0.0.0.0s   255.255.255.255Rk  iD   Ra  iC   R  R   s   message-typeR  RW  Rd  (   s   message-typeR  (   R   Ri  R   R   Rd  R  R  R  R\  R1  R  R  (   Rd  RA   t   famt   hw(    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   dhcp_request.  s    R  Rn
  c         C   s   y x t  t d |   t d t    t d | d t d t d |  g   d d d	 d
 d d d d } t | j o t |  GHPn | d  j o
 d GHPn d | t i
 i | t i f GH| t i
 } q Wn t j
 o n Xd  S(   NR  Rk  Rm
  Ro
  RX
  RI  R  i   R  i   R  i    R>  s
   No answerss	   %-40s: %r(   R  R\  R1  R.  R
  RZ
  RU
  R2  R  R   RI  RB   R   R  (   R  RI  Rm
  Rg   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   snmpwalk.  s    e c         C   s7  t  t d |   t d |  d d \ } } d } xR | D]J \ } } | i t  p. | i i d j o | | i d  7} q q; q; W| d 7} xe | D]] \ } } | i t  o | | i d	  7} q | i i d j o | | i d
  7} q q W| d 7} x! | D] } | | i d  7} qW| d 7} | S(   sP   portscan a target and output a LaTeX table
report_ports(target, ports) -> stringR  Ra  R  i   s    \begin{tabular}{|r|l|l|}
\hline
i   s   %TCP.sport% & open & SA \\
s   \hline
sO   %TCPerror.dport% & closed & ICMP type %ICMP.type%/%ICMP.code% from %IP.src% \\
s*   %TCP.sport% & closed & TCP %TCP.flags% \\
s    %TCP.dport% & ? & unanswered \\
s   \hline
\end{tabular}
(   R  R\  R0  R<  R2  R  R  RU  (   R   R  R   R*  t   repR   Rg   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   report_ports.  s(    . 
 
 
c            sp  h    h  } h  }	 h  }
 h  } d } x | D] } t  t | |   \ } } } t t |  |  } t   i | d  t |  t |     | <d  | | <| |	 | | f <q+ W  i   } | i   } | o | i |  nG y | i d    Wn/ y | i d    Wq&| i   q&Xn X| o | i |  nG y | i d    Wn/ y | i d    Wq| i   qXn X| o* | | t    f d   |   } | GHn |  |  } | d Gx. | D]& } |   |  |
 | <|
 | | GqW| GH| o	 | GHn xJ | D]B } | | Gx, | D]$ } |
 | |	 i | | f d  Gq+W| GHqW| o	 | GHn d  S(	   Ni    c         S   s   t  |   t  |  S(    (   Rr   (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   /  s    c         S   s   t  t |   t |   S(    (   R  R   (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   /  s    c         S   s   t  |   t  |  S(    (   Rr   (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   /  s    c         S   s   t  t |   t |   S(    (   R  R   (   R6   RJ   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   /  s    c            s     |  S(    (    (   R6   (   t   vx(    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   !/  s    R   R~  (   RN   R   R  Rq   R   R   RQ   RR  (   t   yfmtfunct   fmtfunct   endlineR   t   fxyzt   sortxt   sortyt   seplinefunct   vyt   vzt   vxft   vyfR   R|   R   R   t   zzt   vxkt   vykt   seplineRE  R6   RJ   (    (   R  sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyt   __make_table.  sl     .
!	 	  "	c          O   s    t  d   d   d |  |  d  S(   Nc         S   s   d  |  S(   s   %%-%is(    (   R   (    (    sB   /home/jmjones/local/Projects/psabook/oreilly/network/code/scapy.pyRK   5/  s    R   (   R	  (   R\   RA   (    (    sB   /home/jmjones/local/Projects/psabook/ore
