课程目标
-
完成基础知识练习
-
print+input+if+while+判断符号>>>猜数字游戏
-
random+print+while+format+判断符号>>>彩票游戏
-
open+readlines+def函数>>>卖包子
-
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安全开发之基础知识综合练习【C09课】
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论