Senior Network Programming 2

1. Install package wireshart 
2.udp is broadcast, tcp not. Broadcast, it might produce the broadcast storm
Broadcast is the need to use, you do not need to do

two .tcp protocol, the Transmission Control Protocol. udp, User Datagram Protocol
tcp is stable, we can ensure that the data received, with respect to the udp slower
web server, usually using tcp. tcp scenarios more

servers:
1. Create a socket socket ()
2. Bind the bind ()
3. listen listen () socket becomes passive and active speaking socket
4.accept () receives, waiting for others to carry on call

client:
socket ()
client ()

network communication process
is inscribed: open the browser process, the process of www.baidu.com input
process packet tracer of
downloading software professlonal XP Windows

1. two computers can communicate with the premise that in the same network segment
2. Why can not multiple computers connected network cable
3. switches and hubs

between different networks can communicate, no communication between the inter-network
routers: link different network

mac address of the device in two communication, change. ip address in the whole communication will not change
mac address is used for data transfer between hand in hand, in addition to this useless

visit Baidu browser 1. Problem
1. see whether the gateway
2. Look at the ip or domain names, ip, then that is three-way handshake
3. If the domain name, needs to resolve the corresponding baidu ip address
4, arp get mac address of the default gateway
5. Organization data sent to the default gateway
6. The default network have the ability to forward data, the router forwards the data to
7. a router according to a routing protocol, to select an appropriate path quickly, the gateway forwards the data to the destination
object gateway (NM server resides dns), forwards the data to the server dns
dns query the server baidu.com parse out the corresponding ip address, and send him to backtrack client to request the domain name
after obtaining the corresponding ip address baidu.com, it will send tcp three-way handshake, link
using the http protocol to send data requests to the web server
4. after the web server receives a request for data, the corresponding results by querying its own server, backtrack to the browser
after receiving the data browser, the browser's own rendering function to display the mesh
browser is closed tcp link, namely this wave 4
to complete the access process

tcp three-way handshake, waving four
three-way handshake and fourth wave can not Successful direct impact on the accept (), linking
to shake hands three times, four times during the wave
if you do not wave, it will consume resources

length link
long link is continuing to access
a process can have an unlimited number of sockets

the service side the maximum number of links maximum number of links to 5, the client 20, the server once the data received is five
maximum linux is that you set, according to the configuration inside the kernel

network attacks
dns attack
distinguish phishing sites, look at the domain name is correct, and then enter a false password

nslookup + domain name corresponding to the domain name to see which ip
Python using raw sockets

# Server 
from Socket Import *
# Create a set rhythm. 1, which use TCP SOCK_STREAM
serverSocket = Socket (AF_INET, SOCK_STREAM)
# 2 bind any ip address, port number 8899
ServerSocket.bind (( '', 8899))
#. 3 for monitor, from the active becomes passive, which the number is positive you can
serverSocket.listen (5)

# client is only one socket server with two
clientSocket = socket (AF_INET, SOCK_STREAM)
clientSocket.connect (( ' 192.168.0.107 ', 8899))

#. 4 receives return data, a return value is equal tuples, the first value is a new socket, the other of the second value is ip and port
#clientSocket represented new client end
#clientinfo represents a new client and port
clientSocket.send ( 'haha'.encode (' UTF-. 8 '))

the clientSocket,, the clientInfo serverSocket.accept = ()
# receiving 1024 bytes
Print (. 1)

recvDate the clientSocket, =. the recv (1024)
Print ( "% S:% S"% (STR (the clientInfo), recvDate))
# Close current socket
clientSocket.close ()
# close the package socket
serverSocket.close ()

# tcp client
# client is only one socket server with two
# tcpLliebtSocket = socket (AF_INET, SOCK_STREAM )


# Tcp client 
from socket Import *

# client is only one socket server with two
clientSocket = socket (AF_INET, SOCK_STREAM)
#tcp client has to condense a good server, so in future data transmission, do not need to fill in each other's ip and port
#udp when sending data, because there is no previous connection, it is necessary to be accepted in every ip and port to send the summary
clientSocket.connect (( '192.168.0.107', 8989 ))
transmission data #
clientSocket.send ( 'haha'.encode (' UTF-. 8 '))
recvData = clientSocket.recv (1024)
Print (' recvData: S% '% recvData)
clientSocket.close ()
# Server 
from Socket Import *
# Create a set rhythm. 1, which use TCP SOCK_STREAM
serverSocket = Socket (AF_INET, SOCK_STREAM)
# 2 bind any ip address, port number 8899
ServerSocket.bind (( '', 8800))
#. 3 listening, the active becomes passive, which number is a positive number can
serverSocket.listen (. 5)
#. 4 receives return data, a return value is equal tuples, the first value is a new socket, the second the value of each other's ip and port number
#clientSocket represent a new client
#clientinfo represent a new client and port
clientSocket, clientInfo = serverSocket.accept ()
# to accept 1024 byte
recvDate = clientSocket.recv (1024)
Print ( " S%:% S "% (str (clientInfo), recvDate))
# close the current socket

# client is only one socket server with two
clientSocket = socket (AF_INET, SOCK_STREAM)
#tcp client has well servers to condense, so in future data transmission, does not need to fill in each other's ip and port
#udp time in sending data, because there is no previous connection, it is necessary to be accepted in every ip and port to send the summary
clientSocket.connect (( '192.168.0.107', 8989))
# transmits data
clientSocket.send ( 'haha'.encode (' UTF-. 8 '))
recvData = clientSocket.recv (1024)
Print (' recvData:% S '% recvData)
clientSocket.close ()


clientSocket.close ()
# close the package socket
serverSocket.close ()




Guess you like

Origin www.cnblogs.com/wangjunxi/p/11832218.html