This commit is contained in:
Stefan Schwarz 2021-02-06 12:43:23 +01:00
commit 45244050ea
6 changed files with 82 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
eval "$(lorri direnv)"

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/env/

9
Dockerfile Normal file
View file

@ -0,0 +1,9 @@
FROM python:3.8
WORKDIR /app
RUN true \
&& pip install dnspython matrix-nio
ADD . /app
CMD python key.py

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# dnswatch
Watch a bunch of domains for changes

57
key.py Normal file
View file

@ -0,0 +1,57 @@
import asyncio
import os
import time
import dns.resolver
from nio import AsyncClient
class App:
def __init__(self, user="", password="", room_id="", records=[]):
self.user = user
self.password = password
self.room_id = room_id
self.records = records
self.cache = {}
self.resolver = dns.resolver.Resolver()
self.resolver.nameservers = ['8.8.8.8']
self.client = AsyncClient("https://doesnt.social", self.user)
async def setup(self):
status = await self.client.login(self.password)
print(status)
print("i will be monitoring: {self.records}")
await self.send_message("hi there, i'm marvin")
async def send_message(self, message: str):
await self.client.room_send(
room_id=self.room_id,
message_type="m.room.message",
content={"msgtype": "m.text", "body": message},
)
async def run(self):
await self.setup()
while True:
await self.update()
time.sleep(60)
async def update(self):
for record in self.records:
print(f"checking {record}")
results = self.resolver.resolve(record)
results = [str(r) for r in results]
results.sort()
if results != self.cache.get(record, []):
await self.send_message(f"records for {record} updated: {results}")
self.cache[record] = results
if __name__ == "__main__":
app = App(
user=os.environ["USER"],
password=os.environ["PASSWORD"],
room_id=os.environ["ROOM_ID"],
records=os.environ["RECORDS"].split(","),
)
asyncio.get_event_loop().run_until_complete(app.run())

11
shell.nix Normal file
View file

@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.bashInteractive
(pkgs.python38.withPackages (ps: [
ps.dnspython
ps.matrix-nio
]))
];
}