@ -1,6 +1,6 @@
|
||||
%# -*- coding: utf-8-unix -*-
|
||||
%======================================================================
|
||||
%% qbook.cfg for Qbook Template
|
||||
%% Book Configurations
|
||||
%======================================================================
|
||||
\ProvidesFile{qbook.cfg}[2019/03/19 v1.00 Qbook configuration file]
|
||||
\def\q@contentsname{目~~~~录}
|
@ -0,0 +1,120 @@
|
||||
%# -*- coding: utf-8-unix -*-
|
||||
%=========================================================================
|
||||
% instructions.tex for Computer Network Assigenment & Project Instructions
|
||||
%=========================================================================
|
||||
% 双面打印
|
||||
% \documentclass[fontset=fandol]{../format/instructions}
|
||||
\documentclass[]{instructions}
|
||||
\addbibresource{../bib/main.bib} % 导入参考文献数据库
|
||||
\begin{document}
|
||||
\pagestyle{empty}
|
||||
\input{../data/cover} % 载入封面
|
||||
|
||||
%=========================================================================
|
||||
% 版本声明
|
||||
\clearpage
|
||||
\begin{center}
|
||||
\Large{\sffamily\bfseries\heiti Version 0.4} \\ \vspace{2em}
|
||||
\Large{\sffamily\bfseries\heiti 发布日期: \today} \\ \vspace{1em}
|
||||
\end{center}
|
||||
|
||||
% \vfill
|
||||
% \vspace{30em}
|
||||
% \begin{tabular*}{\textwidth}{ccc}
|
||||
% \includegraphics{figure/by-nc.eps}
|
||||
% & \begin{minipage}[b]{0.6\textwidth}
|
||||
% \small\sffamily
|
||||
% 本作品采用知识共享 署名-非商业性使用 4.0 国际许可协议进行许可。\\
|
||||
% 访问~\href{http://creativecommons.org/licenses/by-nc/4.0/}{此链接}~查看该许可协议。
|
||||
% \end{minipage}
|
||||
% \end{tabular*}
|
||||
|
||||
%=========================================================================
|
||||
% 前言
|
||||
\thispagestyle{empty}
|
||||
\frontmatter % 对前言和概览用罗马数字作为页码
|
||||
\pagestyle{empty}
|
||||
\input{../data/preface}
|
||||
|
||||
%=========================================================================
|
||||
% 目录
|
||||
\cleardoublepage
|
||||
\pagestyle{empty}
|
||||
\tableofcontents
|
||||
\mainmatter % 对正文用阿拉伯数字作为页码
|
||||
|
||||
%======================================================================
|
||||
% 正文内容
|
||||
\pagestyle{fancy}
|
||||
\setcounter{page}{1}
|
||||
|
||||
% “网络抓包与协议分析”
|
||||
\graphicspath{{../figure/chapters/wireshark/}}
|
||||
\input{../data/ch_wireshark/preface}
|
||||
\input{../data/ch_wireshark/sec_arp}
|
||||
\input{../data/ch_wireshark/sec_ip}
|
||||
\input{../data/ch_wireshark/sec_tcp}
|
||||
|
||||
% “基于套接字的网络程序设计”
|
||||
\graphicspath{{../figure/chapters/socket/}}
|
||||
\input{../data/ch_socket/preface}
|
||||
\input{../data/ch_socket/sec_udp}
|
||||
\input{../data/ch_socket/sec_web}
|
||||
\input{../data/ch_socket/sec_smtp}
|
||||
|
||||
|
||||
% “组网基础”
|
||||
\graphicspath{{../figure/chapters/ensp/}}
|
||||
\input{../data/ch_ensp/preface}
|
||||
\input{../data/ch_ensp/sec_static}
|
||||
\input{../data/ch_ensp/sec_rip}
|
||||
\input{../data/ch_ensp/sec_ospf}
|
||||
|
||||
% “路由器实现”
|
||||
\graphicspath{{../figure/chapters/router-openbox/}}
|
||||
\input{../data/ch_router-openbox/preface}
|
||||
\input{../data/ch_router-openbox/sec_switch}
|
||||
\input{../data/ch_router-openbox/sec_router}
|
||||
\input{../data/ch_router-openbox/sec_networking}
|
||||
|
||||
% “软件定义网络与网络测量”
|
||||
\graphicspath{{../figure/chapters/sdn-openbox/}}
|
||||
\input{../data/ch_sdn-openbox/preface}
|
||||
\input{../data/ch_sdn-openbox/sec_sdn}
|
||||
\input{../data/ch_sdn-openbox/sec_topo}
|
||||
\input{../data/ch_sdn-openbox/sec_ns}
|
||||
|
||||
|
||||
%=========================================================================
|
||||
% 附录
|
||||
\appendix
|
||||
\titleformat{\chapter}[display]{\flushleft}{
|
||||
\begin{tikzpicture}
|
||||
\node[anchor=south west] (chap) at (0,1.3){
|
||||
\Large\heiti {附录\Alph{chapter}}};
|
||||
\path [left color=c1,right color=c3] (0,-0.3) rectangle (\textwidth,-0.5);
|
||||
\path(0,-0.2);
|
||||
\end{tikzpicture}
|
||||
}{-30mm}{\Huge\heiti}
|
||||
\titlespacing{\chapter}{0pt}{0pt}{2\baselineskip}
|
||||
\renewcommand{\thefigure}{\Alph{chapter}--\arabic{figure}}
|
||||
\renewcommand{\thetable}{\Alph{chapter}--\arabic{table}}
|
||||
\renewcommand{\chaptername}{附录\Alph{chapter}}
|
||||
|
||||
\graphicspath{{../figure/appendixes/ensp/}}
|
||||
\input{../data/appendix/ensp}
|
||||
|
||||
\graphicspath{{../figure/appendixes/openbox/}}
|
||||
\input{../data/appendix/openbox}
|
||||
|
||||
\graphicspath{{../figure/appendixes/fast/}}
|
||||
\input{../data/appendix/fast}
|
||||
|
||||
\backmatter
|
||||
%======================================================================
|
||||
% 参考文献
|
||||
% \printbibliography[heading=bibintoc]
|
||||
% \makeatletter
|
||||
% \makeatother
|
||||
|
||||
\end{document}
|
@ -0,0 +1,66 @@
|
||||
from socket import *
|
||||
from base64 import *
|
||||
|
||||
mailfrom = "mail from:2@test.com\r\n"
|
||||
rcptto = "rcpt to:1@test.com\r\n"
|
||||
data = "data\r\n"
|
||||
quitmsg = "quit\r\n"
|
||||
|
||||
msg = "\r\n I love computer networks!"
|
||||
endmsg = "\r\n.\r\n"
|
||||
#此处使用易邮邮件服务器软件搭建了一个内网邮件服务器
|
||||
mailserver = '10.130.82.62'
|
||||
mailport = 25
|
||||
connectaddress = (mailserver, mailport)
|
||||
# Create socket called clientSocket and establish a TCP connection with mailserver
|
||||
clientSocket = socket(AF_INET, SOCK_STREAM)
|
||||
clientSocket.connect(connectaddress)
|
||||
|
||||
recv = clientSocket.recv(1024)
|
||||
print (recv)
|
||||
if recv[:3] != '220':
|
||||
print ('220 reply not received from server.')
|
||||
# Send HELO command and print server response.
|
||||
heloCommand = 'HELO Alice\r\n'
|
||||
clientSocket.send(bytes(heloCommand.encode()))
|
||||
recv1 = clientSocket.recv(1024)
|
||||
print (recv1.decode())
|
||||
if recv1[:3] != '250':
|
||||
print ('250 reply not received from server.')
|
||||
|
||||
#print('000000000000000')
|
||||
#从命令和打印服务器响应发送邮件。
|
||||
login = b'auth login\r\n'
|
||||
clientSocket.send(login)
|
||||
recv2 = clientSocket.recv(1024).decode('utf-8')
|
||||
print ('222+',recv2)
|
||||
|
||||
userCommand = b64encode('2@test.com'.encode('utf-8'))
|
||||
clientSocket.send((str(userCommand,encoding='utf-8')+'\r\n').encode())
|
||||
recv3 = clientSocket.recv(1024).decode('utf-8')
|
||||
print ('333+',recv3)
|
||||
|
||||
password = b64encode('2'.encode('utf-8'))
|
||||
clientSocket.send((str(password,encoding='utf-8')+'\r\n').encode())
|
||||
recv4 = clientSocket.recv(1024).decode('utf-8')
|
||||
print ('444+',recv4)
|
||||
|
||||
#print('0000000000000000')
|
||||
|
||||
clientSocket.send(bytes(mailfrom.encode()))
|
||||
check = clientSocket.recv(1024)
|
||||
print(check)
|
||||
clientSocket.send(bytes(rcptto.encode()))#将RCPT发送到命令和打印服务器响应。
|
||||
check1 = clientSocket.recv(1024)
|
||||
print(check1)
|
||||
clientSocket.send(bytes(data.encode()))#发送数据命令和打印服务器响应。
|
||||
check2 = clientSocket.recv(1024)
|
||||
print(check2)
|
||||
clientSocket.send(bytes((mailfrom+msg+endmsg).encode()))#发送消息数据。
|
||||
check3 = clientSocket.recv(1024)
|
||||
print(check3)
|
||||
#发送退出命令并获得服务器响应。
|
||||
clientSocket.send(bytes(quitmsg.encode()))
|
||||
check4 = clientSocket.recv(1024)
|
||||
print(check4)
|
||||
clientSocket.close()
|
@ -0,0 +1,19 @@
|
||||
from socket import *
|
||||
import time
|
||||
serverName = 'localhost'
|
||||
serverPort = 12000
|
||||
clientSocket = socket(AF_INET, SOCK_DGRAM)
|
||||
clientSocket.settimeout(1)
|
||||
|
||||
for i in range(0, 10):
|
||||
sendTime = time.time()
|
||||
message = ('Ping %d %s' % (i + 1, sendTime)).encode()
|
||||
try:
|
||||
clientSocket.sendto(message, (serverName, serverPort))
|
||||
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
|
||||
rtt = time.time() - sendTime
|
||||
print('Sequence %d: Reply from %s RTT = %.3fs' % (i + 1, serverName, rtt))
|
||||
except Exception as e:
|
||||
print('Sequence %d: Request timed out' % (i + 1))
|
||||
|
||||
clientSocket.close()
|
@ -0,0 +1,11 @@
|
||||
import random
|
||||
from socket import *
|
||||
serverSocket = socket(AF_INET, SOCK_DGRAM)
|
||||
serverSocket.bind(('', 12000))
|
||||
while True:
|
||||
rand = random.randint(0, 10)
|
||||
message, address = serverSocket.recvfrom(1024)
|
||||
message = message.upper()
|
||||
if (rand < 4):
|
||||
continue
|
||||
serverSocket.sendto(message, address)
|
@ -0,0 +1,62 @@
|
||||
# Import socket module
|
||||
from socket import *
|
||||
import sys # In order to terminate the program
|
||||
|
||||
# Create a TCP server socket
|
||||
#(AF_INET is used for IPv4 protocols)
|
||||
#(SOCK_STREAM is used for TCP)
|
||||
|
||||
serverSocket = socket(AF_INET, SOCK_STREAM)
|
||||
|
||||
# Assign a port number
|
||||
serverPort = 80
|
||||
|
||||
# Bind the socket to server address and server port
|
||||
serverSocket.bind(("", serverPort))
|
||||
|
||||
# Listen to at most 1 connection at a time
|
||||
serverSocket.listen(1)
|
||||
|
||||
# Server should be up and running and listening to the incoming connections
|
||||
|
||||
while True:
|
||||
print('The server is ready to receive')
|
||||
|
||||
# Set up a new connection from the client
|
||||
connectionSocket, addr = serverSocket.accept()
|
||||
|
||||
# If an exception occurs during the execution of try clause
|
||||
# the rest of the clause is skipped
|
||||
# If the exception type matches the word after except
|
||||
# the except clause is executed
|
||||
try:
|
||||
# Receives the request message from the client
|
||||
message = connectionSocket.recv(1024).decode()
|
||||
# Extract the path of the requested object from the message
|
||||
# The path is the second part of HTTP header, identified by [1]
|
||||
filename = message.split()[1]
|
||||
# Because the extracted path of the HTTP request includes
|
||||
# a character '\', we read the path from the second character
|
||||
f = open(filename[1:])
|
||||
# Store the entire contenet of the requested file in a temporary buffer
|
||||
outputdata = f.read()
|
||||
# Send the HTTP response header line to the connection socket
|
||||
connectionSocket.send("HTTP/1.1 200 OK\r\n\r\n".encode())
|
||||
|
||||
# Send the content of the requested file to the connection socket
|
||||
for i in range(0, len(outputdata)):
|
||||
connectionSocket.send(outputdata[i].encode())
|
||||
connectionSocket.send("\r\n".encode())
|
||||
|
||||
# Close the client connection socket
|
||||
connectionSocket.close()
|
||||
|
||||
except IOError:
|
||||
# Send HTTP response message for file not found
|
||||
connectionSocket.send("HTTP/1.1 404 Not Found\r\n\r\n".encode())
|
||||
connectionSocket.send("<html><head></head><body><h1>404 Not Found</h1></body></html>\r\n".encode())
|
||||
# Close the client connection socket
|
||||
connectionSocket.close()
|
||||
|
||||
serverSocket.close()
|
||||
sys.exit()#Terminate the program after sending the corresponding data
|
Before Width: | Height: | Size: 178 KiB |
Before Width: | Height: | Size: 459 KiB After Width: | Height: | Size: 459 KiB |
Before Width: | Height: | Size: 242 KiB After Width: | Height: | Size: 242 KiB |
Before Width: | Height: | Size: 894 KiB After Width: | Height: | Size: 894 KiB |
After Width: | Height: | Size: 255 KiB |
After Width: | Height: | Size: 226 KiB |
After Width: | Height: | Size: 223 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 1.5 MiB |
After Width: | Height: | Size: 1.5 MiB |
After Width: | Height: | Size: 1.5 MiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 241 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 735 KiB |
After Width: | Height: | Size: 127 KiB |
After Width: | Height: | Size: 220 KiB |
After Width: | Height: | Size: 184 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 135 KiB |
After Width: | Height: | Size: 114 KiB |
After Width: | Height: | Size: 132 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 97 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 73 KiB |
Before Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 92 KiB |
Before Width: | Height: | Size: 189 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 94 KiB |
Before Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 138 KiB |
Before Width: | Height: | Size: 84 KiB |
Before Width: | Height: | Size: 280 KiB |
Before Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 145 KiB |
Before Width: | Height: | Size: 145 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 10 KiB |