资源简介
计算机网络-自顶向下方法第七版(配套资源)
代码片段和文件信息
from socket import *
import os
import sys
import struct
import time
import select
import binascii
ICMP_ECHO_REQUEST = 8
def checksum(string):
csum = 0
countTo = (len(string) // 2) * 2
count = 0
while count < countTo:
thisVal = ord(string[count+1]) * 256 + ord(string[count])
csum = csum + thisVal
csum = csum & 0xffffffff
count = count + 2
if countTo < len(string):
csum = csum + ord(string[len(string) - 1])
csum = csum & 0xffffffff
csum = (csum >> 16) + (csum & 0xffff)
csum = csum + (csum >> 16)
answer = ~csum
answer = answer & 0xffff
answer = answer >> 8 | (answer << 8 & 0xff00)
return answer
def receiveOnePing(mySocket ID timeout destAddr):
timeLeft = timeout
while 1:
startedSelect = time.time()
whatReady = select.select([mySocket] [] [] timeLeft)
howLongInSelect = (time.time() - startedSelect)
if whatReady[0] == []: # Timeout
return “Request timed out.“
timeReceived = time.time()
recPacket addr = mySocket.recvfrom(1024)
# Fetch the ICMPHeader from the IP
icmpHeader = recPacket[20:28]
rawTTL = struct.unpack(“s“ bytes([recPacket[8]]))[0]
# binascii -- Convert between binary and ASCII
TTL = int(binascii.hexlify(rawTTL) 16)
icmpType code checksum packetID sequence = struct.unpack(“bbHHh“ icmpHeader)
if packetID == ID:
byte = struct.calcsize(“d“)
timeSent = struct.unpack(“d“ recPacket[28:28 + byte])[0]
return “Reply from %s: bytes=%d time=%f5ms TTL=%d“ % (destAddr len(recPacket) (timeReceived - timeSent)*1000 TTL)
timeLeft = timeLeft - howLongInSelect
if timeLeft <= 0:
return “Request timed out.“
def sendOnePing(mySocket destAddr ID):
# Header is type (8) code (8) checksum (16) id (16) sequence (16)
myChecksum = 0
# Make a dummy header with a 0 checksum
# struct -- Interpret strings as packed binary data
header = struct.pack(“bbHHh“ ICMP_ECHO_REQUEST 0 myChecksum ID 1)
data = struct.pack(“d“ time.time())
# Calculate the checksum on the data and the dummy header.
myChecksum = checksum(str(header + data))
# Get the right checksum and put in the header
if sys.platform == ‘darwin‘:
# Convert 16-bit integers from host to network byte order
myChecksum = htons(myChecksum) & 0xffff
else:
myChecksum = htons(myChecksum)
header = struct.pack(“bbHHh“ ICMP_ECHO_REQUEST 0 myChecksum ID 1)
packet = header + data
mySocket.sendto(packet (destAddr 1)) # AF_INET address must be tuple not str
# Both LISTS and TUPLES consist of a number of objects
# which can be referenced by their position number within the object.
def doOnePing(destAddr timeout):
icmp = getprotobyname(“icmp“)
# SOCK_RAW is a powerful socket type. For more details: http://sock-raw.org/papers/sock_raw
mySocket = socket(AF_INET SOCK_RAW icmp)
myID = os.getpid() & 0xFFFF # Return the current process i
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\
文件 222 2016-05-26 16:27 resources\599710134312805_Pythonsol-260138\__MACOSX\._Solutions
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\
文件 120 2016-05-26 16:27 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._.DS_Store
文件 222 2015-03-09 12:07 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._IcmpPing
文件 222 2015-03-09 12:07 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._ProxyServer
文件 222 2015-03-09 12:07 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._SMTPClient
文件 222 2015-03-09 12:07 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._StreamingVideo
文件 222 2015-03-16 09:56 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._Traceroute
文件 222 2015-03-09 12:07 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._UDPPinger
文件 222 2015-03-09 12:07 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\._Webserver
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\IcmpPing\
文件 222 2015-03-08 16:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\IcmpPing\._IcmpPing.py
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\ProxyServer\
文件 222 2015-03-07 19:24 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\ProxyServer\._ProxyServer.py
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\SMTPClient\
文件 222 2015-03-07 20:24 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\SMTPClient\._SMTPClient.py
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\StreamingVideo\
文件 222 2015-03-09 11:39 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\StreamingVideo\._Client.py
文件 222 2015-03-08 09:39 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\StreamingVideo\._RtpPacket.py
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\Traceroute\
文件 222 2015-03-16 09:56 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\Traceroute\._Traceroute.py
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\UDPPinger\
文件 222 2015-03-08 17:08 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\UDPPinger\._UDP_Pinger_Client.py
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\Webserver\
文件 222 2015-03-06 17:00 resources\599710134312805_Pythonsol-260138\__MACOSX\Solutions\Webserver\._Websever.py
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\Solutions\
文件 6148 2016-05-26 16:27 resources\599710134312805_Pythonsol-260138\Solutions\.DS_Store
目录 0 2018-11-29 22:31 resources\599710134312805_Pythonsol-260138\Solutions\IcmpPing\
文件 3625 2015-03-08 16:31 resources\599710134312805_Pythonsol-260138\Solutions\IcmpPing\IcmpPing.py
............此处省略47个文件信息
相关资源
- 天天跑酷美术资源素材.zip
- 资源.rar
- 《Photoshop CS6图像设计案例教程》书籍
- 2018信息夏令营资源
- OPC Client 开发资源包
- 北航961初试资料 真题+ppt+期中期末+教
- 炉石传说全套美术资源卡牌+UI
- 国土资源数据2000国家大地坐标系转换
- ADAMS 2016虚拟样机技术从入门到精通(
- 山东大学软件学院数据库期末考试复
- RabbitMQ资源包
- 2013 duilib入门简明教程 整个工程(含
- jdk1.8资源
- 乐优商城图片资源
- 双人夺宝系统精简版.zip
- 计算机网络自顶向下中文第6版.pdf
- Unity仙侠游戏,3D资源宠物、坐骑、怪
- 数据链路层协议设计[BUPT]计算机网络
- NI ELVIS的通信课程实验资源包.zip
- Cisco Packet Tracer 6.0简体中文版.rar
-
该资源是windows server2012R2 netfr
amewo - 计算机网络自顶向下方法.第6版清晰版
- Unity的基础Standard Assets资源包
- CSS禅意花园PDF+源码含资源文件
- 匿名飞控代码解读汇总 配套资源-> 匿
- 解惑SDN独家资源
- 计算机网络自顶向下方法
- opencv2计算机视觉编程手册书籍+源代码
- opencv 3.4.X 编译 ffmpeg和ippicv相关资源
- Unity射击游戏资源包
评论
共有 条评论