iwla

iwla Commit Details

Date:2020-05-11 10:03:07 (2 months 23 days ago)
Author:Grégory Soutadé
Branch:dev
Commit:6f9622bb911a41aba36910a8f08475201d28da7d
Parents: afc6f0218198783e0df2ded36c64536f0e21ac5f
Message:Bugfix : iptogeo : _send_request that must handles timeout errors (empty packets) was not used

Changes:
Mplugins/post_analysis/iptogeo.py (3 diffs)

File differences

plugins/post_analysis/iptogeo.py
5353
5454
5555
56
57
58
56
57
5958
6059
60
61
6162
6263
6364
......
112113
113114
114115
115
116
116117
117
118
118
119119
120120
121121
122122
123
124
125
126
127
123
124
125
126
127
128
129
130
131
132
133
128134
129135
130136
......
140146
141147
142148
143
144
145
146
147
148
149
150
151
149
152150
153151
154152
self._remote_port = remote_port
self._timeout = timeout
self._family = family
self._nb_requests_sent = 0
self._create_socket()
self._nb_requests_sent = self.MAX_REQUESTS # Force socket creation
self._socket = None
def _create_socket(self):
if self._socket:
self._socket.close()
self._socket = socket.socket(self._family, socket.SOCK_STREAM)
if not self._timeout is None:
self._socket.settimeout(self._timeout)
return (ip_res, '%c%c%c%c' % (cc0, cc1, cc2, cc3))
def _send_request(self, packet):
def _send_request(self, packet, second_chance=True):
self._nb_requests_sent += 1
if self._nb_requests_sent == self.MAX_REQUESTS:
self.close()
if self._nb_requests_sent >= self.MAX_REQUESTS:
self._create_socket()
self._nb_requests_sent = 0
try:
self._socket.send(packet)
except IOError, e:
# Give another chance (we may have been disconnected due to timeout)
self._create_socket()
self._socket.send(packet)
packet = self._socket.recv(IPToGeo.PACKET_SIZE)
if not packet:
raise socket.timeout
return packet
except socket.timeout, e:
if second_chance:
self._nb_requests_sent = self.MAX_REQUESTS
return self._send_request(packet, False)
else:
raise e
def ip_to_geo(self, ip):
ip_type = IPToGeo.IPV4
if ip.find('.') >= 0:
raise Exception('Bad IP %s' % (ip))
packet = self._create_request(splitted_ip, ip_type)
try:
self._socket.send(packet)
except IOError, e:
# Give another chance (we may have been disconnected due to timeout)
self._create_socket()
self._socket.send(packet)
packet = self._socket.recv(IPToGeo.PACKET_SIZE)
if not packet:
raise IPToGeoException('Error, empty packet')
packet = self._send_request(packet)
(ip, country_code) = self._check_request(packet)
if country_code:
# convert to string

Archive Download the corresponding diff file

Branches

Tags