| arprequest/README |
| 21 | 21 | >>> ar2.request() |
| 22 | 22 | False |
| 23 | 23 | |
| 24 | Changelog |
| 25 | --------- |
| 26 | |
| 27 | 0.3 : |
| 28 | |
| 29 | - You can now select type of ARP request. This is done with "arp_type" |
| 30 | argument of ArpRequest class. You can use arprequest.ARP_GRATUITOUS |
| 31 | to make an ARP Gratuitous request (what is currently done) or use |
| 32 | arprequest.ARP_STANDARD to do a standard ARP request. |
| 33 | |
| 34 | This option was created to use this library with systems which are |
| 35 | configured to block Arp Gratuitous. |
| 36 | |
| 24 | 37 | Constraints |
| 25 | 38 | ----------- |
| 26 | 39 | |
| ... | ... | |
| 28 | 41 | unix signals. |
| 29 | 42 | - ArpRequest work only as root, because it uses raw sockets. |
| 30 | 43 | - Module is commented in french. I will translate comments in english, |
| 31 | | a day... |
| 44 | some day... |
| 32 | 45 | |
| arprequest/arprequest.py |
| 20 | 20 | from struct import pack, unpack |
| 21 | 21 | import signal |
| 22 | 22 | |
| 23 | ARP_GRATUITOUS = 1 |
| 24 | ARP_STANDARD = 2 |
| 25 | |
| 23 | 26 | def val2int(val): |
| 24 | 27 | '''Retourne une valeur sous forme d'octet en valeur sous forme |
| 25 | 28 | d'entier.''' |
| ... | ... | |
| 60 | 63 | class ArpRequest: |
| 61 | 64 | '''Génère une requête ARP et attend la réponse''' |
| 62 | 65 | |
| 63 | | def __init__(self, ipaddr, if_name): |
| 66 | def __init__(self, ipaddr, if_name, arp_type=ARP_GRATUITOUS): |
| 64 | 67 | # Initialisation du socket (socket brut, donc besoin d'ê root) |
| 68 | self.arp_type = arp_type |
| 69 | self.if_ipaddr = socket.gethostbyname(socket.gethostname()) |
| 70 | |
| 65 | 71 | self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, |
| 66 | 72 | socket.SOCK_RAW) |
| 67 | 73 | self.socket.bind((if_name, socket.SOCK_RAW)) |
| ... | ... | |
| 86 | 92 | def _send_arp_request(self): |
| 87 | 93 | '''Envois une requête ARP pour la machine''' |
| 88 | 94 | |
| 95 | # Adresse logicielle de l'émetteur : |
| 96 | if self.arp_type == ARP_STANDARD: |
| 97 | saddr = pack('!4B', |
| 98 | *[int(x) for x in self.if_ipaddr.split('.')]) |
| 99 | else: |
| 100 | saddr = pack('!4B', |
| 101 | *[int(x) for x in self.ipaddr.split('.')]) |
| 102 | |
| 103 | |
| 104 | |
| 89 | 105 | # Forge de la trame : |
| 90 | 106 | frame = [ |
| 91 | 107 | ### Partie ETHERNET ### |
| ... | ... | |
| 101 | 117 | pack('!HHBB', 0x0001, 0x0800, 0x0006, 0x0004), |
| 102 | 118 | # Type d'opération (=ARP Request) : |
| 103 | 119 | pack('!H', 0x0001), |
| 104 | | # Adresse matériel de l'éméteur : |
| 120 | # Adresse matériel de l'émetteur : |
| 105 | 121 | self.socket.getsockname()[4], |
| 106 | | # Adresse logicielle de l'émetteur (=adresse IP cible = |
| 107 | | # ARP gratuit) |
| 108 | | pack('!4B', *[int(x) for x in self.ipaddr.split('.')]), |
| 122 | # Adresse logicielle de l'émetteur : |
| 123 | saddr, |
| 109 | 124 | # Adresse matérielle de la cible (=00*6) : |
| 110 | 125 | pack('!6B', *(0,) * 6), |
| 111 | 126 | # Adresse logicielle de la cible (=adresse fournie au |
| arprequest/setup.py |
| 5 | 5 | |
| 6 | 6 | setup( |
| 7 | 7 | name='arprequest', |
| 8 | | version='0.2', |
| 8 | version='0.3', |
| 9 | 9 | description=('A class which sends an ARP Request to know if a ' |
| 10 | 10 | 'host is online on local networks'), |
| 11 | 11 | long_description=ldesc, |
| ... | ... | |
| 14 | 14 | author_email='antoine@inaps.org', |
| 15 | 15 | license='WTFPL', |
| 16 | 16 | py_modules=['arprequest'], |
| 17 | | url='http://dev.inaps.org/trac/wiki/ArpRequest', |
| 17 | url='http://idevelop.org/p/labo/page/ArpRequest/', |
| 18 | 18 | classifiers=[ |
| 19 | 19 | 'Topic :: Communications', |
| 20 | 20 | 'Topic :: System :: Networking', |