aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)