网安
  • Develop
    • JAVA学习
      • 字节码
      • API开发
      • Web开发
      • 工程结构推荐
      • 创建第一个项目
      • 权限管控
      • 配置文件
      • 日志管理
      • 数据访问
      • 性能监控
      • IoC容器
      • Spring
      • Filter与Listener
      • jsp
      • MVC
      • servlet-1
      • servlet-2
      • servlet-3
      • servlet-4
      • FreeMarker
      • Thymeleaf
      • EL
      • SpEL
      • JSTL
      • 部署
      • JDBC
      • 数据库连接池
      • fastjson
      • jackson
      • XML
      • JSON
      • 序列化
      • Maven
      • 安装与使用
      • 工具
      • 爬虫
    • GO学习
      • GO
        • flag 包
        • goland 远程调试
        • GoReleaser
        • OS 包
        • time 包
        • 格式化输出
    • Lua学习
      • Lua
      • 基础语法
      • LuaJIT
      • 与系统交互
    • Pyhon
      • 基础
      • Django
      • CLI
      • miniforge
      • MockingBird
      • pdb
      • pyc
      • 装的我脑血栓要犯了
      • Python101
      • 反序列化
      • 爬虫
      • Pillow
      • 图像识别
      • flask
    • Speed-Ruby
      • 入门1
      • 入门2 对象
      • 入门3 创建命令
      • Encoding类
      • File类与Dir类
      • IO
      • Proc类
      • Time类与Date类
      • 正则
      • 错误处理与异常
      • 对象、变量和常量
      • 方法
      • 数值
      • 数组
      • 条件判断
      • 循环
      • 运算符
      • Socket编程
      • 字符串
      • 并发与线程
      • 块
      • 类和模块
      • 散列
    • Web
      • HTTP
        • Connection
        • HTTP 报文
        • Vary
      • 笔记
        • 跳转
        • 认证 & 授权
        • 同源策略(SOP)
        • 文件
    • Git 学习笔记
    • JSON
      • JSON 学习笔记
    • HTML
      • Speed-HTML
      • 语法学习
      • HTML字符实体
    • XML
      • XML 学习笔记
    • 计算机基础
      • 操作系统
      • 计算机组成
      • 算法
      • 内存
      • 字符编码
    • gnuplot 学习笔记
    • regex
  • Integrated
    • Linux
      • God-Linux
      • Secure-Linux
      • Power-Linux
      • IO模型
      • Speed-Linux
      • 发行版
      • 工具
      • 启动过程
      • 进程
      • 认证
      • 日志
      • 守护进程
      • 文件
      • 信息
      • VSFTP 配置案例
      • auditd
      • containerd
      • DNS 配置案例
      • Docker
      • Docker-Compose
      • firewalld 实验
      • gpg
      • Iptables
      • httpd
      • LAMP
      • mysql
      • nfs 配置案例
      • openssl
      • PAM
      • samba 配置案例
      • terraform
      • ufw
      • VSFTP 配置案例
    • Network
      • Speed-Net
      • Power-Net
      • SDN 笔记
      • DNS
      • TLS
    • Windows
      • Secure-Win
      • Speed-Win
      • ACL
      • LDAP
      • IPC$(Internet Process Connection)
      • PDB符号文件
      • 工作组
      • WinRM
      • 角色权限
      • 凭据
      • 签名
      • 日志
      • 认证
      • 协议
      • 信息
      • 应用
      • 组策略
      • 域
      • asp站点搭建
      • Exchange 搭建
      • Windows 故障转移集群
      • Windows 基础服务搭建
      • Windows 域搭建
      • 本地抓包
      • PowerShell 笔记
    • 容器
      • Docker
    • 数据库
      • Speed-SQL
      • Power-SQL
      • MSSQL
      • MySQL
      • Postgresql
      • Redis
      • MySQL大小写问题
      • 主键和外键
      • MySQL快速入门
      • 虚拟化
        • ESXi
        • vCenter
  • Plan
    • Mac-Plan
    • Misc-Plan
    • Team-Plan
    • Thinking-Plan
    • VM-Plan
  • Sercurity
    • Power-PenTest
    • BlueTeam
      • 安全建设
      • 分析
      • 加固
      • 取证
      • 应急
      • USB取证
      • 磁盘取证
      • 内存取证
      • ClamAV 部署
      • yara 实验
      • 安防设施搭建使用
      • ZIP明文攻击
      • 流量分析
    • Crypto
      • Crypto
        • 2020 9 G60攻防大赛
        • CTF
        • 2020 9 中能融合杯工控CTF
        • 2020 10 全国工业互联网安全技术技能大赛江苏省选拔赛
        • 2020 10 全国网络与信息安全管理职业技能大赛江苏场
        • 2020 11 I²S峰会暨工业互联网安全大赛
        • 2021 6 第二届I²S峰会暨工业互联网安全大赛
        • 2021-9-第七届工控信息安全攻防竞赛
        • 2021 9 第七届全国职工职业技能大赛某市县选拔赛
        • 2021 9 全国网络与信息安全管理职业技能大赛江苏场
        • 2021-10-G60攻防大赛
    • CTF
      • CTF
      • writeup
        • 2020 9 中能融合杯工控CTF
        • 2020 9 G60攻防大赛
        • 2020 10 全国工业互联网安全技术技能大赛江苏省选拔赛
        • 2020 10 全国网络与信息安全管理职业技能大赛江苏场
        • 2020 11 I²S峰会暨工业互联网安全大赛
        • 2021 6 第二届I²S峰会暨工业互联网安全大赛
        • 2021-9-第七届工控信息安全攻防竞赛
        • 2021 9 第七届全国职工职业技能大赛某市县选拔赛
        • 2021 9 全国网络与信息安全管理职业技能大赛江苏场
        • 2021-10-G60攻防大赛
    • ICS
      • PLC攻击
      • S7comm 相关
      • 工控协议
      • 上位机安全
      • Modbus 仿真环境搭建
      • siemens 仿真搭建实验
      • S7-300 启停实验
    • IOT
      • 无线电安全
        • RFID复制卡
        • RFID基础知识
        • WiFikiller
      • 硬件安全
        • DIY键盘嵌入指纹识别模块实验记录
        • Device-Exploits
        • HID-Digispark
        • HID-KeyboardLogger
        • HID-USBHarpoon
        • HID-USBKeyLogger
      • 固件安全
        • 固件安全
        • Dlink_DWR-932B 路由器固件分析
    • Mobile sec
      • 小程序安全
      • Android安全
    • PWN
      • SLMail溢出案例
      • PWN
    • Red Team
      • OS安全
        • Linux 安全
        • Exploits
        • NTLM中继
        • Windows 安全
        • Responder欺骗
        • Windows-LOL
      • Web_Generic
        • Top 10
          • RCE
          • Fileread
          • SQLi
          • SSRF
          • SSTI
          • Web Generic
          • XSS
          • XXE
      • Web_Tricks
        • JWT 安全
        • HTTP_request_smuggling
        • OOB
        • 绕过访问
      • 靶场
        • Hello-Java-Sec 学习
        • DVWA-WalkThrough
        • pikachu-WalkThrough
        • upload-labs-WalkThrough
        • XVWA-WalkThrough
        • XSS挑战-WalkThrough
      • 实验
        • flask
        • fastjson
        • Log4j
        • nodejs
        • Shiro
        • Spring
        • Weblogic
      • 前端攻防
      • IDOR
    • 安防设备
      • Exploits
      • Bypass 技巧
    • 后渗透
      • 权限提升
      • 后渗透
      • 权限维持
      • 实验
        • C2 实验
        • Exchange
        • 端口转发实验
        • 代理实验
        • 免杀实验
        • 隧道实验
    • 软件服务安全
      • Exploits
      • CS Exploits
      • 实验
        • Docker
        • Kubernetes
        • Mysql
        • Oracle
        • PostgreSQL
        • Redis
        • vCenter
    • 协议安全
      • Exploits
    • 信息收集
      • 端口安全
      • 空间测绘
      • 信息收集
    • 语言安全
      • 语言安全
        • 语言安全
      • GO安全
        • GO安全
        • Go代码审计
      • JAVA安全
        • JAVA安全
        • JAVA代码审计
        • JAVA反序列化
        • SpEL 注入
      • PHP安全
        • PHP安全
        • bypass_disable_function
        • bypass_open_basedir
        • phpinfo
        • PHP代码审计
        • PHP反序列化
        • PHP回调函数
        • 变量覆盖
        • POP
        • 弱类型
        • 伪协议
        • 无字母数字Webshell
      • Python安全
        • pyc反编译
        • Python安全
        • Python 代码审计
        • 沙箱逃逸
      • dotnet安全
      • JS安全
    • 云安全
      • 公有云安全
    • Reverse
      • Reverse
      • FILE
        • ELF
        • BMP
        • JPG
        • PE
        • PNG
        • ZIP
        • 文件头
      • 实验
        • PYAble
          • 2-逆运算
          • 1-基本分析
          • 3-异或
          • 4-Base64
          • 5-Base64换表
          • 6-动态调试
        • Windows
          • condrv.sys 内存损坏漏洞
    • 工具
      • Aircrack
      • BloodHound
      • Burp Suite
      • frp
      • CobaltStrike
      • Ghidra
      • fscan
      • Hashcat
      • IDA
      • merlin
      • Kali
      • Metasploit
      • Mimikatz
      • ModSecurity
      • Nmap
      • nps
      • nuclei
      • pupy
      • RedGuard
      • SET
      • sliver
      • Snort
      • Sqlmap
      • Suricata
      • Sysmon
      • uncover
      • Volatility
      • Wfuzz
      • Wireshark
      • xray
    • 安全资源
      • 靶机
        • VulnHub
          • DC
            • DC2 WalkThrough
            • DC1 WalkThrough
            • DC3 WalkThrough
            • DC4 WalkThrough
            • DC5 WalkThrough
            • DC6 WalkThrough
            • DC9 WalkThrough
            • DC8 WalkThrough
          • It's_October
            • It’s_October1 WalkThrough
          • Kioptrix
            • Kioptrix2 WalkThrough
            • Kioptrix3 WalkThrough
            • Kioptrix4 WalkThrough
            • Kioptrix5 WalkThrough
          • Mission-Pumpkin
            • PumpkinGarden-WalkThrough
            • PumpkinFestival WalkThrough
            • PumpkinRaising WalkThrough
          • Symfonos
            • symfonos1 WalkThrough
            • symfonos2 WalkThrough
            • symfonos3 WalkThrough
            • symfonos5 WalkThrough
        • Wargames
          • Bandit
            • Bandit-WalkThrough
      • 面试问题
        • 面试问题
Powered by GitBook
On this page
  • 加解密
  • 编码
  • 数值转换
  • 字符串转换
  • 字符串处理
  • 声音
  • 执行系统命令
  • 延时
  • 时间戳
  • 输出
  • 安全脚本
  • Docker Engine SDK
  • mysql
  • oss2
  1. Develop
  2. Pyhon

Python101


加解密

HASH

import hashlib

# md5, sha1, sha224, sha256, sha384, sha512
s = 'hello world'
m = hashlib.md5()
m.update(s.encode('utf8'))
print(m.digest())
print(m.hexdigest())

# ripemd160, whirlpool
s = 'hello world'
m = hashlib.new('ripemd160', s.encode('utf8'))
print(m.digest())
print(m.hexdigest())

RSA gmpy2

import gmpy2

p = 168870409632549765296862502254899759857248288652407554850383477768823119986297924033151555409082356346297282197467254809081931208549224155851315637344747298357415893525472097154103238042019866682938382139834279447488738548244853184293595933654527554670457923545588565351501521501815389298997833861578226633099
q = 136505636991931352215759862754723380107419404176934963805672183755717752956589135238497377957828097441347957566489629211243389022288160648357324629288547621047463026266886900467398707294913322326802718447765393605735412855505214780439471729354761056917299208670362196028628829497574575055117449119342100056517
e = 65537

n = p * q
fn = (p - 1) * (q - 1)
d = gmpy2.invert(e, fn)

# encode
plain = "hello world"
cipher = gmpy2.powmod(int(plain.hex(),16), e, n)
print cipher

# decode
cipher = 17123126358168532314364171789745947147158203528255189528376034042576955961464108007241396193221317579386199055678187296416631757350036173529280264692509105557539380445658352098757386832691606291403716717255406122398828996166165137869000756490419628668837727171987655840934249710275220041791912411702429566338522067039808551028470065040909781794268938955092150084715883613062506445552253043511850366325327543440113474870896494812927181373067664361593089869517445577240126156141735331979758927134194252186254770372018574046630061371952143328299376196926784339615150604268752279279335534713614030849861471450015448322452
plaint = gmpy2.powmod(cipher, d, n)
s = '%x' % plaint
if len(s) % 2 != 0:
    s = '0' + s
print(s)

编码

中文转十六进制

>>> '测试'.encode('utf-8')
b'\xe6\xb5\x8b\xe8\xaf\x95'

字节数组与十六进制

# 字节数组
byte = b'\x01\x02\x03\x04\x05\x06\x07\x08'
byte = b'hello world'

# 十六进制
h = 0x01020304

# 字符串 -> 字节数组
s = 'hello world'
hb = s.encode('utf8')

# 字节数组 -> 字符串
hb = b'\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64'
s = hb.decode('utf8')

二进制格式转换

[0xab, 0xbc, 0xcd, 0xde] -> '\xab\xbc\xcd\xde'

s = [0xab, 0xbc, 0xcd, 0xef]
print(bytes(s))

'\xde\xad\xbe\xef' -> [222, 173, 190, 239]

s = '\xde\xad\xbe\xef'
res = list(s)
# res [222, 173, 190, 239]

'\xab\xbc\xcd\xde' -> 'abbccdde'

s = '\xab\xbc\xcd\xde'
res = binascii.hexlify(s)
# res = abbccdde

'aabbccdd' -> '\xaa\xbb\xcc\xdd'

s = 'aabbccdd'
res = binasicc.unhexlify(s)
# res = \xaa\xbb\xcc\xdd

'\xde\xad\xbe\xef' -> 0xdeadbeef

s = '\xde\xad\xbe\xef'
res = int.from_bytes(s, 'big')
# res = 0xdeadbeef

0xdeadbeef -> '\xde\xad\xbe\xef'

s = 0xdeadbeef
print(int.to_bytes(s, 4, 'big'))

ASCII 转 HEX

import binascii

s = b'fmcd\IRWOCEHRG[OYS[Uh'
print(binascii.b2a_hex(s))
import codecs
codecs.encode(b"c", "hex")

HEX 转 ASCII

import codecs
codecs.decode("7061756c", "hex")

base64 编解码

import base64
>>> base64.b64encode(b'binary\x00string')
b'YmluYXJ5AHN0cmluZw=='
>>> base64.b64decode(b'YmluYXJ5AHN0cmluZw==')
b'binary\x00string'

url safe 的 base64 编解码

>>> base64.b64encode(b'i\xb7\x1d\xfb\xef\xff')
b'abcd++//'
>>> base64.urlsafe_b64encode(b'i\xb7\x1d\xfb\xef\xff')
b'abcd--__'
>>> base64.urlsafe_b64decode('abcd--__')
b'i\xb7\x1d\xfb\xef\xff'

base64 换表

import base64
str1 = "Wj1gWE9xPSGUQ0KCPCGET09WR1qSzZ=="   #str1是要解密的代码

string1 = "ZYXABCDEFGHIJKLMNOPQRSTUVWzyxabcdefghijklmnopqrstuvw0123456789+/"    #string1是改过之后的base64表
string2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

print (base64.b64decode(str1.translate(str.maketrans(string1,string2))))

数值转换

# 字符 -> 十进制
>>> s = 'a'
>>> d = ord(s)
97

# 十进制 -> 字符
>>> d = 97
>>> s = chr(d)
'a'

# 十进制 -> 十六进制
>>> d = 123456
>>> h = hex(d)
'0x1e240'

# 十进制 -> 二进制
>>> d = 123456
>>> b = bin(d)
'0b11110001001000000'

# 十六进制 -> 十进制
>>> h = '1e240'
>>> d = int(h, 16)
123456

>>> h = 0x1e240
>>> print(h)
123456

# 十六进制 -> 二进制
>>> h = 0x1e240
>>> b = bin(h)
'0b11110001001000000'

# 二进制 -> 十进制
>>> b = '11110001001000000'
>>> d = int(b, 2)
123456

>>> b = 0b11110001001000000
>>> print(b)
123456

# 二进制 -> 十六进制
>>> b = 0b11110001001000000
>>> h = hex(b)
'0x1e240'

字符串转换

# 字符串 -> 十六进制字符串
# Python2
>>> s = "hello world"
>>> hs = s.encode('hex')
'68656c6c6f20776f726c64'

# Python3
>>> s = 'hello world'.encode('utf8')
>>> hs = s.hex()
'68656c6c6f20776f726c64'
>>> hs = binascii.hexlify(s)
b'68656c6c6f20776f726c64'

# 字符串 -> 十进制字符串
>>> s = "hello world"
>>> ds = ' '.join(['{:d}'.format(ord(c)) for c in s])
'104 101 108 108 111 32 119 111 114 108 100'

# 字符串 -> 二进制字符串
>>> s = "hello world"
bs = ' '.join(['{0:08b}'.format(ord(c)) for c in s])
'01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'

# 十六进制字符串 -> 字符串
# Python2
>>> hs = '68656c6c6f20776f726c64'
>>> s = hs.decode('hex')
'hello world'
# Python3
>>> hs = '68656c6c6f20776f726c64'
>>> s = bytes.fromhex(hs)
b'hello world'

# 十六进制字符串 -> 十进制字符串
# Python2
>>> hs = '68656c6c6f20776f726c64'
>>> ds = ' '.join(['%d' % int(hs[x*2:x*2+2], 16) for x in range(len(hs)/2)])
'104 101 108 108 111 32 119 111 114 108 100'
# Python3
>>> hs = '68656c6c6f20776f726c64'
>>> ds = ' '.join(['%d' % int(hs[x*2:x*2+2], 16) for x in range(math.floor(len(hs)/2))])
'104 101 108 108 111 32 119 111 114 108 100'

>>> hs = '68 65 6c 6c 6f 20 77 6f 72 6c 64'
>>> ds = ' '.join(['%d' % int(x, 16) for x in hs.split(' ')])
'104 101 108 108 111 32 119 111 114 108 100'

# 十六进制字符串 -> 二进制字符串
# Python2
>>> hs = '68656c6c6f20776f726c64'
>>> bs = ' '.join(['{0:08b}'.format(int(hs[x*2:x*2+2], 16)) for x in range(len(hs)/2)])
'01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'
# Python3
>>> hs = '68656c6c6f20776f726c64'
>>> bs = ' '.join(['{0:08b}'.format(int(hs[x*2:x*2+2], 16)) for x in range(math.floor(len(hs)/2))])
'01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'

>>> hs = '68 65 6c 6c 6f 20 77 6f 72 6c 64'
>>> bs = ' '.join(['{0:08b}'.format(int(x, 16)) for x in hs.split(' ')])
'01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'

# 十进制字符串 -> 字符串
>>> ds = '104 101 108 108 111 32 119 111 114 108 100'
>>> s = ''.join([chr(int(x)) for x in ds.split(' ')])
'hello world'

# 十进制字符串 -> 十六进制字符串
>>> ds = '104 101 108 108 111 32 119 111 114 108 100'
>>> hs = ''.join(['%02x' % int(x) for x in ds.split(' ')])
'68656c6c6f20776f726c64'

# 十进制字符串 -> 二进制字符串
>>> ds = '104 101 108 108 111 32 119 111 114 108 100'
>>> hs = ' '.join(['{0:08b}'.format(int(x)) for x in ds.split(' ')])
'01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'

# 二进制字符串 -> 字符串
>>> bs = '01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'
>>> s = ''.join([chr(int(x, 2)) for x in bs.split(' ')])
'hello world'

# 二进制字符串 -> 十六进制字符串
>>> bs = '01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'
>>> hs = ''.join(['%02x' % int(x, 2) for x in bs.split(' ')])
'68656c6c6f20776f726c64'

# Python2
>>> bs = '0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
>>> hs = ''.join(['%02x' % int(bs[i*8:i*8+8], 2) for i in range(len(bs)/8)])
'68656c6c6f20776f726c64'
# Python3
>>> bs = '0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
>>> hs = ''.join(['%02x' % int(bs[i*8:i*8+8], 2) for i in range(math.floor(len(bs)/8))])
'68656c6c6f20776f726c64'

# 二进制字符串 -> 十进制字符串
>>> bs = '01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100'
>>> ds = ' '.join(['%d' % int(x, 2) for x in bs.split(' ')])
'104 101 108 108 111 32 119 111 114 108 100'

# Python2
>>> bs = '0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
>>> hs = ' '.join(['%d' % int(bs[i*8:i*8+8], 2) for i in range(len(bs)/8)])
'104 101 108 108 111 32 119 111 114 108 100'
# Python3
>>> bs = '0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
>>> hs = ' '.join(['%d' % int(bs[i*8:i*8+8], 2) for i in range(math.floor(len(bs)/8))])
'104 101 108 108 111 32 119 111 114 108 100'

字符串处理

每个字符减 1

string=bytearray(b"gmbh|ZPV`GJOE`JU`IBIB~")
for i in range(len(string)):
    string[i]-=1;
print(string)

数组中每个字符与自身位数异或

data=[0x66,0x6D,0x63,0x64,0x7F,0x5C,0x49,0x52,0x57,0x4F,0x43,0x45,0x48,0x52,0x47,0x5B,0x4F,0x59,0x53,0x5B,0x55,0x68]
for i in range(len(data)):
    data[i]^=i
print(bytearray(data))

十六进制不带 0x 补零 (ASCII 字节类型)

arr = [0x4B, 0x43, 0x09, 0xA1, 0x01, 0x02, 0xAB, 0x4A, 0x43]
def print_bytes_hex(data):
    lin = ['%02X' % i for i in data]
    print(" ".join(lin))
print_bytes_hex(arr)

十六进制不带 0x 补零 (字符串类型)

arr = 'Work'
def print_string_hex(data):
    lin = ['%02X' % ord(i) for i in data]
    print(" ".join(lin))
print_string_hex(arr)

字符串反转

str='test123'
print(str[::-1])

声音

print("\a")

windows

import winsound
duration = 1000     # millisecond
freq = 440          # Hz
winsound.Beep(freq, duration)
# FREQ是频率(以赫兹为单位),而持续时间是毫秒(毫秒)。

linux

apt install speech-dispatcher
import os
os.system('spd-say "your program has finished"')
apt install sox
import os
duration = 1        # second
freq = 440          # Hz
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % (duration, freq))

执行系统命令

os

import os
os.system("whoami")
import os
nowtime = os.popen('whoami')
print(nowtime.read())

commands

import commands
status, output = commands.getstatusoutput('date')
print(output)

延时

sleep()

time.sleep(1)   # 延时1秒

时间戳

time()

time() 返回当前时间的时间戳(1970纪元后经过的浮点秒数)。

print(time.time())

输出

python字符串去掉前缀b

需要去掉字符串的前缀b,只需要进行utf-8的转换即可,即

data = data.decode(“utf-8”).

安全脚本

写 python 目录遍历 POC 时遇到的问题

  • https://mazinahmed.net/blog/testing-for-path-traversal-with-python/


Docker Engine SDK

pip3 install docker

运行一个容器,并执行容器中的一个命令

import docker
client = docker.from_env()
r = client.containers.run("alpine", ["echo", "hello", "world"])
print(str(r, encoding='utf-8'))

列出所有镜像

import docker
client = docker.from_env()
for image in client.images.list():
  print(image.id)

mysql

pip3 install PyMySQL

连接 Mysql 的 TESTDB 数据库

#!/usr/bin/python3
import pymysql

# 打开数据库连接
db = pymysql.connect(host='localhost',
                     user='testuser',
                     password='test123',
                     database='TESTDB')

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()

# 使用 execute()  方法执行 SQL 查询
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()

print ("Database version : %s " % data)

# 关闭数据库连接
db.close()

创建数据库表

#!/usr/bin/python3

import pymysql

# 打开数据库连接
db = pymysql.connect(host='localhost',
                     user='testuser',
                     password='test123',
                     database='TESTDB')

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()

# 使用 execute() 方法执行 SQL,如果表存在则删除
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")

# 使用预处理语句创建表
sql = """CREATE TABLE EMPLOYEE (
         FIRST_NAME  CHAR(20) NOT NULL,
         LAST_NAME  CHAR(20),
         AGE INT,
         SEX CHAR(1),
         INCOME FLOAT )"""

cursor.execute(sql)

# 关闭数据库连接
db.close()

oss2

  • https://help.aliyun.com/document_detail/32027.html

创建examplebucket存储空间

# -*- coding: utf-8 -*-
import oss2

# 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
auth = oss2.Auth('<yourAccessKeyId>', '<yourAccessKeySecret>')
# Endpoint以杭州为例,其它Region请按实际情况填写。
bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>')

# 设置存储空间为私有读写权限。
bucket.create_bucket(oss2.models.BUCKET_ACL_PRIVATE)

上传文件

# -*- coding: utf-8 -*-
import oss2

# 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
auth = oss2.Auth('<yourAccessKeyId>', '<yourAccessKeySecret>')
# Endpoint以杭州为例,其它Region请按实际情况填写。
bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>')

# 上传文件到OSS。
# <yourObjectName>由包含文件后缀,不包含Bucket名称组成的Object完整路径,例如abc/efg/123.jpg。
# <yourLocalFile>由本地文件路径加文件名包括后缀组成,例如/users/local/myfile.txt。
bucket.put_object_from_file('<yourObjectName>', '<yourLocalFile>')
Previous装的我脑血栓要犯了Next反序列化