分类 Python 下的文章

基本语法

ExcelFile = xlrd.open_workbook(‘xls.xls’,formatting_info=True) #绑定XLS
vuln = ExcelFile.sheet_by_index(1) #绑定sheet页
nrows = vuln.nrows #行数
vuln.row_values(x) #提取X行

from openpyxl import Workbook
from openpyxl.styles import Font, colors, Alignment

    wb = Workbook()
    ws = wb.active

    ws['A1'] = 'ip'



    for x in cal_path(s):
        for x in xls(s,split_path(x)[1]):
            ws.append(x)


    ws.row_dimensions.height=20 #调整行高
    ws.column_dimensions.width=40 #调整列高

    wb.save(xxxxx.xls)

Python 利用 reduce判断IP是否为内网IP返回True和False

from functools import reduce

def ip_into_int(ip):
    # 先把 192.168.1.13 变成16进制的 c0.a8.01.0d ,再去了“.”后转成10进制的 3232235789 即可。
    # (((((192 * 256) + 168) * 256) + 1) * 256) + 13
    return reduce(lambda x,y:(x<<8)+y,map(int,ip.split('.')))

def is_internal_ip(ip):
    ip = ip_into_int(ip)
    net_a = ip_into_int('10.255.255.255') >> 24
    net_b = ip_into_int('172.31.255.255') >> 20
    net_c = ip_into_int('192.168.255.255') >> 16
    return ip >> 24 == net_a or ip >>20 == net_b or ip >> 16 == net_c

if is_internal_ip('1.1.1.1') is True:
           pass
else:
          pass

#!/bin/bash
# -*- coding: UTF-8 -*-

import requests
import tomd
import sys

url = "https://secsb.com"
r = requests.get(url)
html = r.content
print tomd.Tomd(html).markdown


把html改为Markdown

FLASK 推送静态文件到客户端

filename = “文件名称”
directory = '文件路径,网上说必须要存储在stats目录下的文件才可以'
response = make_response(send_from_directory(directory, filename, as_attachment=True))
return response