本文整理汇总了Python中prettytable.PrettyTable.align["IP"]方法的典型用法代码示例。如果您正苦于以下问题:Python PrettyTable.align["IP"]方法的具体用法?Python PrettyTable.align["IP"]怎么用?Python PrettyTable.align["IP"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prettytable.PrettyTable
的用法示例。
在下文中一共展示了PrettyTable.align["IP"]方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetAll
# 需要导入模块: from prettytable import PrettyTable [as 别名]
# 或者: from prettytable.PrettyTable import align["IP"] [as 别名]
def GetAll():
args = parse_args()
x = PrettyTable(["IP", "Date", "Request", "Status", "Size", "Referrer", "Agent"])
x.align["IP"] = "l"
x.padding_width = 1
for ipv4, dates, requ, stat, size , refer, agen in itertools.imap(None, get_obj[0], get_obj[1], get_obj[2], get_obj[3], get_obj[4], get_obj[5], get_obj[6]):
x.add_row([ipv4, dates, requ[:20], stat, size, refer[:20], agen[:20]])
return x.get_string()
示例2: sql_page
# 需要导入模块: from prettytable import PrettyTable [as 别名]
# 或者: from prettytable.PrettyTable import align["IP"] [as 别名]
def sql_page():
try:
from prettytable import PrettyTable
import datetime
html = """<!DOCTYPE html>
<html>
<head>
<title>SQL Queries</title>
<style>
body {
font-family: "Lucida Console", Monaco, monospace;
color: #fff;
background: #000000;
}
@media (min-width: 1696px) {
#table { display: block; }
#spo { display: none; }
body { font-size: 1em; }
}
@media (max-width: 1695px) {
#table { display: block; }
#spo { display: none; }
body { font-size: .7em; }
}
@media (max-width: 980px) {
#spo { display: block; }
#table { display: none; }
body { font-size: 1em; }
}
</style>
</head>
<body>
"""
db, cur = iplogger.connectDB()
sql = "SELECT hash, IP, name, hits, js, geo, last_hit FROM ips ORDER BY last_hit"
cur.execute(sql)
fetch = cur.fetchall()
db.commit()
cur.close()
db.close()
header = ['hash', 'IP', 'name','hits','js','geo','last_hit']
table = PrettyTable(header)
table.align["geo"] = "l"
table.align["IP"] = "l"
smart_phone_out = []
for row in fetch:
row = list(row)
row[6] = str(row[6])
table.add_row(row)
spo = [header[i].upper() + ": " + str(row[i]) for i in list(range(len(header)))]
smart_phone_out.append("<br>".join(spo))
smart_phone_out.reverse()
smart_phone_out = '<div id="spo">' + "<br><br><br><br>".join(smart_phone_out) + '</div>'
html += '<div id="table">'+str(table).replace('\n','<br>').replace(' ',' ')+'</div>\n'+ smart_phone_out + "\n</body>\n</html>"
return(html)
except Exception as e:
return(str(e))
示例3: TopIpLocation
# 需要导入模块: from prettytable import PrettyTable [as 别名]
# 或者: from prettytable.PrettyTable import align["IP"] [as 别名]
def TopIpLocation():
args = parse_args()
geo = get_obj[0]
c = collections.Counter(geo)
common = dict(c.most_common(20))
reader = geoip2.database.Reader("GeoLite2-City.mmdb") # Download "GeoLite2-city.mmdb" from
x = PrettyTable(["IP", "Country", "Total Connections"])
x.align["IP"] = "l"
x.padding_width = 1
for ips, values in common.iteritems():
try:
locate_ip = reader.city(ips)
country = locate_ip.country.name
x.add_row([ips, country, values])
except Exception as e:
print e
return x.get_string(start=0,end=10,sortby="Total Connections", reversesort=True)
示例4: StatusXx
# 需要导入模块: from prettytable import PrettyTable [as 别名]
# 或者: from prettytable.PrettyTable import align["IP"] [as 别名]
def StatusXx(i,c,A,B,status_code):
List1 = []
List2 = []
args = parse_args()
occurence ={}
x = PrettyTable([i, c])
x.align["IP"] = "l"
x.padding_width = 1
for j, k in itertools.imap(None, A, B):
if k == status_code:
stat = k
List1.append(j)
List2.append(k)
for item in List1:
if item in occurence:
occurence[item] = occurence.get(item)+1
else:
occurence[item] = 1
for m, count in nsmallest(10, occurence.iteritems(), key=lambda (k,v): (-v,k)):
x.add_row([m[:150], count])
return x.get_string()
示例5: main
# 需要导入模块: from prettytable import PrettyTable [as 别名]
# 或者: from prettytable.PrettyTable import align["IP"] [as 别名]
def main(self):
#主调函数
display_format = displayFormat()
arg_length = len(sys.argv)
if arg_length == 1:
display_format.error_print()
elif arg_length == 2 or arg_length == 3:
infile_name = sys.argv[1]
try:
if arg_length == 3:
lines = int(sys.argv[2])
else:
lines = 0
except IOError as e:
print
print(e)
display_format.error_print()
except ValueError:
print
print("Please Enter A Volid Number !!")
display_format.error_print()
else:
display_format.error_print()
fileAnalysis_obj = analysis_log()
not_true_dict = fileAnalysis_obj.generate_log_report(infile_name)
# out {'1.1.1.1': <__main__.hostInfo object at 0x7ffd3d1cd550>, '2.2.2.2': <__main__.hostInfo object at 0x7ffd3d1cd510>}
log_report = fileAnalysis_obj.return_sorted_list(not_true_dict)
total_ip = len(log_report)
if lines:
log_report = log_report[0:lines]
print('\n')
total_size_sent = display_format.format_size(fileAnalysis_obj.total_size_sent)
total_request_times = fileAnalysis_obj.total_request_times
print('Total IP: %s Total Send Size: %s Total Request Times: %d' % (total_ip, total_size_sent, total_request_times))
print('\n')
X = PrettyTable(['IP', 'Send Size', 'Request Times', 'Request Times%', '200', '301', '302', '304', '400', '401', '403', \
'404', '499', '500', '502', '503', '504'])
X.align["IP"] = "l" # Left align IP
X.padding_width = 1 # One space between column edges and contents (default)
for host in log_report:
list1 = []
times = host[1]['total_request_times']
times_percent = (float(times) / float(total_request_times)) * 100
list1.append("%s" % host[0])
list1.append("%s" % (display_format.format_size(host[1]['total_size_sent'])))
list1.append("%s" % times)
list1.append("%.2f" % float(times_percent))
list2 = [host[1]['200'], host[1]['301'], host[1]['302'], host[1]['304'], host[1]['400'], host[1]['401'], host[1]['403'], \
host[1]['404'], host[1]['499'], host[1]['500'], host[1]['502'], host[1]['503'], host[1]['504']]
list1.extend(list2)
X.add_row(list1)
print(X)
print('\n')
Total_X = PrettyTable(['TIP', 'TSend Size', 'TRequest Times', 'TRequest Times%', 'T200', 'T301', \
'T302', 'T304', 'T400', 'T401', 'T403', 'T404', 'T499', 'T500', 'T502', 'T503', 'T504'])
Total_X.align["T IP"] = "l" # Left align IP
Total_X.padding_width = 1 # One space between column edges and contents (default)
Total_list = []
Total_list.append(total_ip)
Total_list.append(total_size_sent)
Total_list.append(total_request_times)
Total_list.append('100%')
Total_list1 = [fileAnalysis_obj.total_200, fileAnalysis_obj.total_301, fileAnalysis_obj.total_302, fileAnalysis_obj.total_304, \
fileAnalysis_obj.total_400, fileAnalysis_obj.total_401, fileAnalysis_obj.total_403, fileAnalysis_obj.total_404, \
fileAnalysis_obj.total_499, fileAnalysis_obj.total_500, fileAnalysis_obj.total_502, fileAnalysis_obj.total_503, \
fileAnalysis_obj.total_504]
Total_list.extend(Total_list1)
Total_X.add_row(Total_list)
print(Total_X)
print('\n')
display_format.execut_time()
print('\n')