python raw input为什么无法使用raw

Python3.1为何不能使用函数raw_input()
[问题点数:20分,结帖人loveyou0131]
Python3.1为何不能使用函数raw_input()
[问题点数:20分,结帖人loveyou0131]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
本帖子已过去太久远了,不再提供回复功能。中国领先的IT技术网站
51CTO旗下网站
使用python raw socket进行TCP SYN扫描
TCP SYN扫描是端口扫描众多方式中的一种,其他方式包括TCP扫描,UDP扫描,ACK扫描,窗口扫描和FIN扫描等。
作者:jeanphorn来源:CSDN博客| 11:03
1. TCP SYN扫描
端口扫描常用于用于探测服务器或主机开放端口情况,被计算机管理员用于确认安全策略,同时被攻击者用于识别目标主机上的可运作的网络服务。端口扫描是向一定范围的服务器端口发送对应请求,以此确认可使用的端口。虽然其本身并不是恶意的网络活动,但也是网络攻击者探测目标主机服务,以利用该服务的已知漏洞的重要手段。
TCP SYN扫描是端口扫描众多方式中的一种,其他方式包括TCP扫描,UDP扫描,ACK扫描,窗口扫描和FIN扫描等。
TCP SYN扫描是另一种TCP扫描。端口扫描工具不使用操作系统原生网络功能,而是自行生成、发送IP数据包,并监控其回应。这种扫描模式被称为&半开放扫描&,因为它从不建立完整的TCP连接。端口扫描工具生成一个SYN包,如果目标端口开放,则会返回SYN-ACK包。扫描端回应一个RST包,然后在握手完成前关闭连接。如果端口关闭了但未使用过滤,目标端口应该会持续返回RST包。
TCP SYN扫描优点:
给扫描工具全权控制数据包发送和等待回应时长的权力,允许更详细的回应分析。
SYN扫描从不会建立完整的连接。
2. python 代码
使用raw socket进行SYN 洪泛,封装多个函数使其模块化和易于理解。利用结构体可以方便的使用格式化字符串和变量列表来编码数据包。
/bin/env&python &&&&&import&socket &import&sys &import&time &&from&struct&import&* &&&def&checksum(msg): &&&&&s&=&0&&&&&&&&&&for&i&in&range(0,len(msg),2): &&&&&&&&&w&=&(ord(msg[i])&&&&8)&+&(ord(msg[i+1])) &&&&&&&&&s&=&s+w &&&&&&s&=&(s&&16)&+&(s&&&0xffff) &&&&&s&=&~s&&&0xffff&&&&&&return&s &&def&CreateSocket(source_ip,dest_ip): &&&&&try: &&&&&&&&&s&=&socket.socket(socket.AF_INET,&socket.SOCK_RAW,&socket.IPPROTO_TCP) &&&&&except&socket.error,&msg: &&&&&&&&&print&'Socket&create&error:&',str(msg[0]),'message:&',msg[1] &&&&&&&&&sys.exit() &&&&&&&&&&&s.setsockopt(socket.IPPROTO_TCP,&socket.IP_HDRINCL,&1) &&&&&return&s &&&def&CreateIpHeader(source_ip,&dest_ip): &&&&&packet&=&''&&&&&&&&&&&headerlen&=&5&&&&&version&=&4&&&&&tos&=&0&&&&&tot_len&=&20&+&20&&&&&id&=&random.randrange(18000,65535,1) &&&&&frag_off&=&0&&&&&ttl&=&255&&&&&protocol&=&socket.IPPROTO_TCP &&&&&check&=&10&&&&&saddr&=&socket.inet_aton&(&source_ip&) &&&&&daddr&=&socket.inet_aton&(&dest_ip&) &&&&&hl_version&=&(version&&&&4)&+&headerlen &&&&&ip_header&=&pack('!BBHHHBBH4s4s',&hl_version,&tos,&tot_len,&id,&frag_off,&ttl,&protocol,&check,&saddr,&daddr) &&&&&&return&ip_header &&&def&create_tcp_syn_header(source_ip,&dest_ip,&dest_port): &&&&&&&&&&source&=&random.randrange(32000,62000,1)&&&&&&&&&seq&=&0&&&&&ack_seq&=&0&&&&&doff&=&5&&&&&&&&&&fin&=&0&&&&&syn&=&1&&&&&rst&=&0&&&&&psh&=&0&&&&&ack&=&0&&&&&urg&=&0&&&&&window&=&socket.htons&(8192)&&&&&&&&&check&=&0&&&&&urg_ptr&=&0&&&&&offset_res&=&(doff&&&&4)&+&0&&&&&tcp_flags&=&fin&+&(syn&&1)&+&(rst&&2)&+&(psh&&3)&+&(ack&&4)&+&(urg&&5) &&&&&tcp_header&=&pack('!HHLLBBHHH',&source,&dest_port,&seq,&ack_seq,&offset_res,&tcp_flags,&window,&check,&urg_ptr) &&&&&&&&&&source_address&=&socket.inet_aton(&source_ip&) &&&&&dest_address&=&socket.inet_aton(&dest_ip&) &&&&&placeholder&=&0&&&&&protocol&=&socket.IPPROTO_TCP &&&&&tcp_length&=&len(tcp_header) &&&&&psh&=&pack('!4s4sBBH',&source_address,&dest_address,&placeholder,&protocol,&tcp_length); &&&&&psh&=&psh&+&tcp_ &&&&&tcp_checksum&=&checksum(psh) &&&&&&&&&&&tcp_header&=&pack('!HHLLBBHHH',&source,&dest_port,&seq,&ack_seq,&offset_res,&tcp_flags,&window,&tcp_checksum,&urg_ptr) &&&&&return&tcp_header &&&def&range_scan(source_ip,&dest_ip,&start_port,&end_port)&: &&&&&syn_ack_received&=&[]&&&&&&&&&for&j&in&range&(start_port,&end_port)&: &&&&&&&&&s&=&CreateSocket(source_ip,&dest_ip) &&&&&&&&&ip_header&=&CreateIpHeader(source_ip,&dest_ip) &&&&&&&&&tcp_header&=&create_tcp_syn_header(source_ip,&dest_ip,j) &&&&&&&&&packet&=&ip_header&+&tcp_header &&&&&&&&&&s.sendto(packet,&(dest_ip,&0)) &&&&&&&&&&data&=&s.recvfrom(1024)&[0][0:] &&&&&&&&&&ip_header_len&=&(ord(data[0])&&&0x0f)&*&4&&&&&&&&&ip_header_ret&=&data[0:&ip_header_len&-&1] &&&&&&&&&tcp_header_len&=&(ord(data[32])&&&0xf0)&&2&&&&&&&&&tcp_header_ret&=&data[ip_header_len:ip_header_len+tcp_header_len&-&1] &&&&&&&&&&if&ord(tcp_header_ret[13])&==&0x12:&&&&&&&&&&&&&&syn_ack_received.append(j) &&&&&return&syn_ack_received &&&&open_port_list&=&[] &ipsource&=&'192.168.1.95'&ipdest&=&'192.168.1.31'&start&=&100&stop&=&450&step&=&(stop-start)/10&scan_ports&=&range(start,&stop,&step) &if&scan_ports[len(scan_ports)-1]&&&stop: &&&&&scan_ports.append(stop) &for&i&in&range(len(scan_ports)-1): &&&&&opl&=&range_scan(ipsource,&ipdest,&scan_ports[i],&scan_ports[i+1]) &&&&&open_port_list.append(opl) &for&i&in&range(len(open_port_list)): &&&&&print&'Process&#:&',i,'&Open&ports:&',open_port_list[i] &print&'A&list&of&all&open&ports&found:&'&for&i&in&range(len(open_port_list)): &&&&&for&j&in&range(len(open_port_list[i])): &&&&&&&&&print&open_port_list[i][j],',&'&
【编辑推荐】【责任编辑: TEL:(010)】
大家都在看猜你喜欢
专题专题专题专题专题
24H热文一周话题本月最赞
讲师:12人学习过
讲师:64人学习过
讲师:821人学习过
精选博文论坛热帖下载排行
本书第1版曾被KDnuggets的读者评选为最受欢迎的数据挖掘专著,是一本可读性极佳的教材。它从数据库角度全面系统地介绍了数据挖掘的基本概念...
订阅51CTO邮刊6581人阅读
使用input和raw_input都可以读取控制台的输入,input()只能接受int,float或由它们组成的表达式:
Python 2.7.5 (default, Mar 19 :16)
[GCC 4.5.4] on linux2
Type &help&, &copyright&, &credits& or &license& for more information.
&&& input(&input something: &)
input something: 123
&&& input(&input something: &)
input something: abc
Traceback (most recent call last):
File &&stdin&&, line 1, in &module&
File &&string&&, line 1, in &module&
NameError: name 'abc' is not defined
input和raw_input在处理数字时是有区别的:
1.输入为纯数字时
input返回的是数值类型,如int,float
raw_inpout返回的是字符串类型,string类型
print &how old are you?&
age1 = input()
print &%r& % age1
age2 = raw_input()
print &%r& % age2
返回结果:
how old are you?
'22' //raw_input()把输入整形当做字符串处理
2.输入字符串为表达式
input会计算在字符串中的数字表达式,而raw_input不会。
sum = input()
print &%r& % sum
sum = raw_input()
print &%r& % sum
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1185382次
积分:11849
积分:11849
排名:第838名
原创:319篇
转载:123篇
评论:355条
(1)(1)(7)(3)(4)(6)(1)(2)(3)(1)(5)(4)(8)(6)(2)(4)(1)(6)(11)(11)(15)(15)(16)(18)(29)(13)(29)(23)(19)(27)(16)(21)(23)(11)(9)(22)(20)(5)(1)(4)(1)(10)(9)Python采用raw_input读取输入值的方法
投稿:shichen2014
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了Python采用raw_input读取输入值的方法,对初学者有很好的学习借鉴价值,需要的朋友可以参考下
本文较为详细的介绍了python中raw_input的用法,使用raw_input 能够很方便的丛控制台读入数据。具体用法示例如下:
1.输入字符串
nID = raw_input("Input your id plz")
if len(nID) != len("01****"):
print 'wring length of id,input again'
print 'your id is %s' % (nID)
2.输入整数
nAge = int(raw_input("input your age plz:\n"))
if nAge & 0 and nAge & 120:
print 'thanks!'
print 'bad age'
print 'your age is %d\n' % nAge
3.输入浮点型
fWeight = 0.0
fWeight = float(raw_input("input your weight\n"))
print 'your weight is %f' % fWeight
4.输入16进制数据
nHex = int(raw_input('input hex value(like 0x20):\n'),16)
print 'nHex = %x,nOct = %d\n' %(nHex,nHex)
5.输入8进制数据
nOct = int(raw_input('input oct value(like 020):\n'),8)
print 'nOct = %o,nDec = %d\n' % (nOct,nOct)
本文示例对Python初学者有一定的学习借鉴价值,感兴趣的读者可以动手调试运行一下本文示例,以加深对raw_input用法的认识。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(1253)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'利用Python和PIL库读取raw格式图像',
blogAbstract:'试了多次终于成功了,放在这里,免得以后忘了。
import Image
file = open(\"image.data\", \"rb\")rawdata = file.read()
# 下面这句是关键,各参数意义如下,
# \"F\" 指定图像的mode为“F”
#& (512,512)为 图像大小
# rawdata 为存放数据的变量
# \"raw\" 指定图像为raw格式
# \"F;32F\" 指定数据在内存中的格式,为32位浮点型im = Image.fromstring(\"F\", (512,512), rawdata, \"raw\", \"F;32F\") # 如此im中就保存的读入的数据,但并没有做格式和类型转换',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:7,
publishTime:3,
permalink:'blog/static/',
commentCount:8,
mainCommentCount:2,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 python中raw input 的文章

 

随机推荐