🤬
  • ■ ■ ■ ■ ■ ■
    Projects/0_UDP_server/README.md
     1 +# UDP server just to receive messages
     2 +>the focus of this challenge was the server, but without the client you would spend more work to test
     3 + 
     4 +https://user-images.githubusercontent.com/32443720/133181445-82ca16e0-a9ff-4eb1-b01a-c21e6dc64be9.mp4
     5 + 
     6 +## :information_source: technologies used
     7 + 
     8 +* Python
     9 + 
     10 +## :information_source: How use?
     11 +```bash
     12 +# Clone the repository
     13 +$ git clone https://github.com/kurogai/100-redteam-projects
     14 + 
     15 +# Enter the repository
     16 +$ cd 100-redteam-projects/0_UDP_server
     17 + 
     18 +# Open a terminal and run
     19 +$ python3 UDPserver.py
     20 + 
     21 +# Open a new terminal and run
     22 +$ python3 UDPclient.py
     23 +```
     24 + 
     25 +## :books: References
     26 + https://www.youtube.com/watch?v=Cr-tPf-MUgI&list=WL&index=12
     27 +
     28 + https://pythontic.com/modules/socket/udp-client-server-example
     29 + 
     30 + 
     31 +## Developer
     32 + 
     33 +[<img src="https://avatars.githubusercontent.com/u/32443720?v=4" width=115 > <br> <sub> Augusto Savi </sub>](https://github.com/AugustoSavi) |
     34 +| :---: |
     35 + 
  • ■ ■ ■ ■ ■ ■
    Projects/0_UDP_server/UDPclient.py
     1 +import socket
     2 + 
     3 +serverAddressPort = ("127.0.0.1", 20001)
     4 +bufferSize = 1024
     5 + 
     6 +# Create a UDP socket at client side
     7 +UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
     8 + 
     9 + 
     10 +while True:
     11 + msgFromClient = input("Send Some text to UDP Server: ")
     12 + bytesToSend = str.encode(msgFromClient)
     13 + 
     14 + # Send to server using created UDP socket
     15 + UDPClientSocket.sendto(bytesToSend, serverAddressPort)
     16 + 
     17 + message, address = UDPClientSocket.recvfrom(bufferSize)
     18 + msg = "\nMessage from Server: {} \n".format(message.decode('UTF-8'))
     19 + 
     20 + print(msg)
  • ■ ■ ■ ■ ■ ■
    Projects/0_UDP_server/UDPserver.py
     1 + 
     2 +import socket
     3 + 
     4 +localIP = "127.0.0.1"
     5 +localPort = 20001
     6 +bufferSize = 1024
     7 +msgFromServer = "Message received on UDP Client and sending it again: "
     8 + 
     9 +# Create a datagram socket
     10 +UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
     11 + 
     12 +# Bind to address and ip
     13 +UDPServerSocket.bind((localIP, localPort))
     14 + 
     15 +print("UDP server up and listening")
     16 + 
     17 +# Listen for incoming datagrams
     18 +while(True):
     19 + message, address = UDPServerSocket.recvfrom(bufferSize)
     20 + 
     21 + print("\nMessage from Client:{0} \nClient IP Address:{1} \n".format(message.decode('UTF-8'),address))
     22 + 
     23 + bytesTosend = msgFromServer + message.decode('UTF-8')
     24 + # Sending a reply to client
     25 + UDPServerSocket.sendto(str.encode(bytesTosend), address)
Please wait...
Page is in error, reload to recover