import socket
def start_server():
host = '127.0.0.1' # Localhost
port = 12345 # Arbitrary non-privileged port
# Creating a socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to a public host, and a well-known port
server_socket.bind((host, port))
# Enable the server to accept connections
server_socket.listen(5)
print(f"Server is listening on host:port")
while True:
# Wait for a connection
client_socket, addr = server_socket.accept()
print(f"Got a connection from addr")
# Receive data from the client
data = client_socket.recv(1024)
print(f"Received: data.decode()")
# Log the IP address
with open("ip_log.txt", "a") as log_file:
log_file.write(f"addr[0]\n")
client_socket.close()
if __name__ == "__main__":
start_server()
You can embed the HTML into any site you own, but embedding into a third-party platform (without permission) may violate their terms of service.
If the goal is to demonstrate how easily IP addresses can be spoofed or to educate on network security, consider using tools and scripts that simulate IP spoofing in a controlled environment.