usr bin env python coding utf-8 from db import oracle_db import sys ti

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from db import oracle_db
import sys, time, calendar
try:
db = oracle_db()
except:
print "can't connect to database (%s)" % sys.exc_value
sys.exit(1)
input = open("Банлист.csv", "r")
while True:
line = input.readline()
if not line: break
line = line.strip().replace('"', '').split(";")
if line[1] == "не нужно":
continue
ip, comment = line[0], line[2]
if ip[0:2] != "10" or ip[len(ip)-1] == "*":
continue
date = comment[comment.find("[")+1:comment.find("]")]
date = date[0:8]
sql = """SELECT distinct(login) FROM fastcom.IT_T_DEACTIVATED_PORTS
WHERE
IP = '%s'
AND UP_TIME BETWEEN TO_DATE('%s 00:00:00', 'DD/MM/YY HH24:MI:SS') AND
TO_DATE('%s 23:59:59', 'DD/MM/YY HH24:MI:SS')
""" % (ip, date, date)
logins = db.fetchall(sql)
if len(logins) == 0:
print "%s;%s;%s" % (ip, "логин не найден", line[2])
continue
if len(logins) != 1:
print "%s;%s;%s" % (ip, "несколько логинов", line[2])
continue
login = logins[0]["LOGIN"]
sql = """SELECT distinct(IP) FROM fastcom.IT_T_DEACTIVATED_PORTS
WHERE
LOGIN = '%s'
AND UP_TIME > TO_DATE('11.04.2008 10:00:00', 'DD.MM.YYYY HH24:MI:SS')
AND IP IS NOT NULL
""" % login
ips = db.fetchall(sql)
newip = ""
for ip_ in ips:
newip += ip_["IP"] + ", "
newip = ip[0:len(ip)-2]
print "%s;%s;%s" % (ip, newip, line[2])