If the conditions are met, I print a message indicating that a ping was received from the specified source IP. I then extract the IP header from the packet and check if the packet is an ICMP ping from the specified source IP address (10.0.0.1) and destined for the loopback address (127.0.0.1). Inside the infinite loop, I receive packets using recvfrom. I then bind the socket to the loopback interface ("lo") using the bind method. ![]() Listen_for_ping("10.0.0.1")In this code, I created a raw socket using the socket.socket function with the AF_PACKET address family. # Start listening for pings from 10.0.0.1 on the loopback interface ![]() # Check if the packet is an ICMP ping from the specified source IPĪnd destination_address = "127.0.0.1" # Loopback addressĪnd packet = 1 # ICMP protocol (1 is for ICMP)Īnd packet = 8 # ICMP type 8 is Echo Request (ping) Source_address = socket.inet_ntoa(ip_header)ĭestination_address = socket.inet_ntoa(ip_header) # Unpack the source and destination IP addresses from the header Sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3)) # Create a raw socket using AF_PACKET address family Here's an example code snippet that demonstrates how you can achieve this: import socket To listen for ICMP ping packets originating from a specific IP address (such as 10.0.0.1) on the loopback interface in Python, you can use the socket module along with the AF_PACKET address family. I want a simple ip address listener, that listens to ip address loopback for a ping sourced from 10.0.0.1 ~ any tips? Any suggestions on how to do this? I read back last summer on socket programming and have done a few tutorials, but these usually refer to just that: socket programming, establishing connections, and binding to ports. The python listener will then trigger based on a ping from 10.0.0.1. (they can traceroute ports, which i may try to implement later). I'm using routers to send a ping, and they can't ping ports. I want to listent to any messages, or ICMP pings sourced from address 10.0.0.1, as the 10.0.0.0 network is an internal network which shoots off a ping to the loopback in cases of network congestion. ![]() (May-23-2023, 08:30 PM)billykid999 Wrote: I want to listent to my loopback address on my windows PC, without attaching it to a port.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |