Need a Python script that listens on an IP port and logs attempts to connect to a file
Posted on 2012-03-28
We have recently decommissioned a machine that was acting as a DNS server. Many of the computers in our large office used this as a DNS server. We have tried to go to each machine and edit the DNS settings to point to our new DNS servers but we've missed some workstations / devices.
I'd like to setup a temporary computer to the old DNS server's IP address and run a little python script that will listen on port 53 for incoming packets and when encountered writes a line to a text file which indicates either the ip address of the requesting machine or the MAC address or both and simply drops the packet without responding.
For someone with the expertise (not me) this would probably be a 20 line script.
The reason I'd like to use python is the abilty to use the same script (slightly modified) for monitoring other ports and situations. (e.g. if we move an SQL server we can listen on that port for incoming requests on the old server. Log the requests and find which computers need to be updated with the new location.)
Ideally the script would have something like:
MonitoredPort = 53
LogFile = "DNS_Requests_log"
[some code to open the port and listen on it]
[code that writes date-time and IP address to LogFile when a packet arrives]
Any pointers would be appreciated.