Python安全开发之基础知识综合练习【C09课】

admin 2021年12月14日10:49:39评论100 views字数 1511阅读5分2秒阅读模式

课程目标

  1. 完成基础知识练习

  2. print+input+if+while+判断符号>>>猜数字游戏

  3. random+print+while+format+判断符号>>>彩票游戏

  4. open+readlines+def函数>>>卖包子

  5. split+replace+readlines+sockets>>>批量获取域名对应ip并保存

使用小栗子,对前面课程内容知识点,框架的综合运用,方便理解运用与加深记忆

核心知识


猜数字


a = 10
while 1:
b = int(input('请输入数字:'))
if a == b:
print('猜对了~~')
break
elif a>b:
print('猜小了哦')
else:
print('猜大了哦')


彩票游戏


import random,time

CP = '{}{}{}{}{}{}'.format(random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9))
print('第一期彩票号码为:{}'.format(CP))
time.sleep(2)
count = 1
while 1:
CS = '{}{}{}{}{}{}'.format(random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9))
count +=1
print('第{}次买彩票,猜测号码为:{}'.format(count,CS))
if CS == CP:
print('第{}次买彩票 猜中啦'.format(count))
break


卖包子


import random
def Mbz(user):
print('用户:{} 买了 {} 个包子'.format(user.ljust(10),random.randint(1,50)))

f = open('用户.txt','r',encoding='utf-8')
fd = f.readlines()
f.close()
for i in fd:
Mbz(i.strip())


综合运用

了解socket模块的其中一个功能,获取网址对应的ip

domains = [x.strip() for x in open('domains.txt','r',encoding='utf-8').readlines()]
import socket
results = set()
for domain in domains:
try:
s = socket.gethostbyname(domain)
print('域名:{} 对应IP为:{}'.format(domain,s))
results.add('.'.join(str(s).split('.')[0:-1])+'.0/24n')
except:
print('获取IP失败')
print(results)
with open('ips.txt','a+',encoding='utf-8')as a:
a.writelines(results)


往期推荐

Python实现404页面识别实践

Python识别CMS与批量资产收集拓展

Sqlmap速查表/功能移植/Python批量检测SQL注入

Nmap/Masscan/Python/端口服务检测/速查表

WEB漏洞本地靶场资源整理

Python打包EXE方法汇总整理

Python中常见需求与完成方法



本文始发于微信公众号(安全研发):Python安全开发之基础知识综合练习【C09课】

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月14日10:49:39
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Python安全开发之基础知识综合练习【C09课】https://cn-sec.com/archives/441837.html

发表评论

匿名网友 填写信息