aboutsummaryrefslogtreecommitdiff
path: root/iploc.py
diff options
context:
space:
mode:
authorPaul Sokolovsky <paul.sokolovsky@linaro.org>2016-01-11 00:54:54 +0200
committerPaul Sokolovsky <paul.sokolovsky@linaro.org>2016-01-11 00:54:54 +0200
commitca57e3a4b236e0e4f3825747ae1bea45d4465aff (patch)
treeac96a529df2f75a0963951cdd2489ef2e79d6b11 /iploc.py
parente9c9b5f2a22ba3f17498248466cee67c3021532e (diff)
iploc.py: Make robust to error while processing single line.
Report exception and continue. Change-Id: I190b5b09527209bbd7a9c921633d4b0438080b1e
Diffstat (limited to 'iploc.py')
-rw-r--r--iploc.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/iploc.py b/iploc.py
index 7e91362..c7d2993 100644
--- a/iploc.py
+++ b/iploc.py
@@ -11,6 +11,7 @@ import sys
import os
import optparse
import socket
+import traceback
from bsddb3 import db
@@ -92,16 +93,21 @@ def main(file_names):
locations = []
match = re.search('\d+\.\d+\.\d+\.\d+\s[^ ]+\s[^ ]+', line)
if match:
- raw_data = match.group()
- data = raw_data.split()
- ip = get_reverse_dns(data[0]) or data[0]
- ident = data[1]
- user = data[2]
- rec = IP2LocObj.get_all(data[0])
- country_short = rec.country_short
- region = rec.region
- city = rec.city
- isp = rec.isp
+ try:
+ raw_data = match.group()
+ data = raw_data.split()
+ ip = get_reverse_dns(data[0]) or data[0]
+ ident = data[1]
+ user = data[2]
+ rec = IP2LocObj.get_all(data[0])
+ country_short = rec.country_short
+ region = rec.region
+ city = rec.city
+ isp = rec.isp
+ except Exception as e:
+ print("Exception while processing line: '%s'" % line)
+ traceback.print_exc()
+ print("Continuing with the next line")
if country_short != '-':
locations.append(country_short)