Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Python Raw SocketʹÓÃʾÀý(·¢ËÍTCP SYNÊý¾Ý°ü)

˵ʵ»°£¬PythonÕæµÄ²»Ì«ÊʺÏ×öÕâÖÖ¶þ½øÖƵĶ«Î÷£¬ÌìÉúûÓÐÖ¸Õ룬µ¼ÖÂÔÚC/C++ºÜÈÝÒ׵Ķ«Î÷ÔÚPythonϾͺÜÂé·³¡£²»¹ýºÃÏñ3.1ÓÐÁËÔ­ÉúµÄbytesÀàÐÍ£¬²»ÖªµÀÄܲ»ÄܸıäÏÖ×´¡£
import sys
import time
import socket
import struct
import random
def SendPacketData (Buffer = None , DestIP = "127.0.0.1" , DestPort = 0) :
"""SendPacketData"""

if Buffer is None :
return False

try:
Socket = socket.socket(socket.AF_INET,socket.SOCK_RAW)
Socket.setsockopt(socket.IPPROTO_IP,socket.IP_HDRINCL,1)
Socket.setsockopt(socket.SOL_SOCKET,socket.SO_SNDTIMEO,2000)

except:
Socket.close()
return False

try:
Socket.sendto(Buffer,0,(DestIP , DestPort))

except:
Socket.close()

return True
def SetPacketAddress (Number = 1) :
"""SetPakcetAddress"""

return [".".join(["%d" % random.randint(1 , 0xFF) for i in range(0,4)]) for n in range(0 , Number)]
def SetPacketData (Length = 32) :
"""SetPacketData"""
return "".join(["%s" % chr(random.randint(0 , 255)) for n in range(Length)])
def SetPacketCheckSum (Buffer = None) :
"""SetPacketCheckSum"""

if Buffer == None :
return False

if len(Buffer) % 2 :
Buffer += '\0'
return ~sum([(ord(Buffer[n + 1]) << 8) + ord(Buffer[n]) for n in range(0 , len(Buffer) , 2)])
#or return ~sum([ord(Buffer[n]) + ord(Buffer[n + 1]) * 256 for n in range(0 , len(Buffer) , 2)])
def SynSendInit (DestIP = "127.0.0.1" , DestPort = 80) :
"""SynSendInit"""

IpHdrLen = 20
TcpHdrLen = 20

IpVerlen = (4 << 4 | IpHdrLen / 4)
IpTotal_len = socket.htons(IpHdrLen + TcpHdrLen)

IpDestIP = struct.unpack('i',socket.inet_aton(DestIP))[0]
IpSourceIP = struct.unpack('i',socket.inet_aton(SetPacketAddress()[0]))[0]

TcpSport = socket.htons(random.randint(1024 , 65000))
TcpDport = socket.htons(DestP


Ïà¹ØÎĵµ£º

PythonÈëÃŵÄ36¸öÀý×Ó Ö® 18

Àý1£º
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 019
# ʹÓÓimport”Óï¾äµ÷ÓÃÄ£¿é£º
import _018_Module
_ ......

´©Ô½Python Challenge

 µÚ¾Å¹Ø Image
    ´ÓÒ³ÃæÉϵÄͼƬ¿ÉÒÔ¿´µ½ÓÐÒ»´®µã£¬ÄÇôÊDz»ÊÇ´ú±í¸Ã¹ØÓëͼÏñµãÓйأ¿ ÎÒÃÇ´ÓÒ³ÃæÔ´Âë¿ÉÒÔ¿´µ½£¬ÓÐÁ½¶ÎÊý×ÖÐòÁÐfirstºÍsecond£¬¶øÓÐÒ»¸öÌáʾfirst+second=? ʲôÒâË¼ÄØ£¿ÄѵÀÊÇ˵(first, second)´ú±íÁËͼÏñµãµÄ×ø±ê£¿²»Ïñ£¬Á½¶ÎÐòÁеij¤¶ÈÓкܴó²îÒì¡£ÄÇôËã·û+»¹ÓÐʲôº¬ÒåÄØ£¬Óп ......

ÔÚWindowsÉϰ²×°Python+MySQL µÄ³£¼ûÎÊÌâ¼°½â¾ö·½·¨

ÑéÖ¤ÊÇ·ñÒѾ­°²×°ÁËMySQLdb£º
==========================================================
d:\usr\local\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] onwin32
Type "help", "copyright", "credits" or "license" for ......

linux²Ù×÷ϵͳ°²×°python3

Ê×ÏÈÊÇÏÂÔØpython3£¬ÏÖÔÚµÄ×î¸ß°æ±¾ÊÇ3.1.1
for linux¡£
ÎҵķÅÖ÷¾¶ÊÇ/home/pythonÏ·ÅÖÃPython-3.1.1.tgz,Ö´ÐÐÒÔÏÂϵÁвÙ×÷£º
1.½âѹ£ºtar zxvf Python-3.1.1.tgz----Éú³É½âѹ°üPython-3.1.1
2.ת»»µ½Python-3.1.1·¾¶Ï£¬Ö´ÐÐ./configure
3.make
4.make install
ÔÚrehl5ÖÐÒѾ­Ä¬Èϰ²×°ÁËpython2.4,ËùÒÔÒª×öÈçÏ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ