A Hundred Days of Code, Day 023, Day 24 - Tiny Utility to do comparative DNS Lookups

Problem - Compare domain lookups, against DoH Servers Take a list of domains (one per line) from a text file as input, find the IP address for the domain using the standard system level DNS, and then check against DoH answers from both cloudflare and google. and say if all answers match properly or not. Notes What do I need to do? (checklist) Get a list of popular websites, (probably Alexa) figure out a way to read them in loop through each line, and look up its ip with the local dns (use the sockets module) with Google’s DoH json endpoint (use the requests module) with Cloudflare’s DoH json endpoint (ditto like Google) Compare all the values. Print if they match or not. Experience I should commit my work often. This took me two days, because I lost all of yesterday’s progress in a computer hiccough. The program runs well. It intentionally limits itself to only the first result in the Google and Cloudflare lookups. I should learn to focus more on what is at hand and not overthink the program. I should be learning to build primitive little, handy dandy tools, not giant cathedrals. I spent two hours fiddling with a way to create another program that would process files for me. (and abandoned it) I need to read the documentation across sites very carefully. They are written with experienced programmers in mind, and not beginners like me. For e.g. When I was trying to look up domain names with Cloudflare, I blindly copied the example and then wondered why it was not giving me the appropriate replies. I then realised I was missing a seperate parameter, &ct=application/dns-json which was quite clearly listed above, but not in the example below. (which in truth was listed, but as part of the command at the command line and I, like a dumbass, just copied the requisite code to adapt to my Python program. Lesson: Cargo cult with extreme caution) Which leads back to the fact, that I should stick to what is assigned, because just doing that much at this stage is taking me a long time. Improvements and features can wait until I am much more fluent. I realise I am trusting autocomplete too much, and I should at least look at what I am completing. I spent 40 minutes, wondering why my comparisons were not working, when in fact, I was using the wrong variables. Lost loads of time with typos. Be more intentional. More slow. Code. Put your sitenames into a file called dumpsites.txt Run check-ip.py ...

August 1, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 022 - Getting into the Groove

Did the same time as yesterday. Only about an hour. Was much more prodcutive though. Getting the hang of how to sit and program and work through things I do not know. Gaining a bit of experience with the workflow now. I have the basics in hand. I know what I want to look up. So check problem, work a bit, look up, try, fail, repeat, gain incremental success, work some more. Love the feedback loop too. With other stuff I try, I have to wait days, weeks, months. Here, it’s immediate. ...

July 30, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 021 - Swing and a miss

Only did about an hour of distracted work and exercises today. I’ll still count it though. Tomorrow is another day :)

July 29, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 020 - Setting up an Editor for Python Development

Had given myself a day, to see if I could get a good Python development environment using Elpy and Emacs. It does work. Just not well enough for me. At the end of the day today, I was happy I learnt so much about Emacs. But that is not my focus right now. Python is. Emacs knowledge can come slowly and organically. So I have kept Emacs as my regular editor for nearly everything text. And switched to the community edition of Pycharm for all my Python projects. ...

July 28, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 019 - Future Exercise Addendum

Ok, think I have the problem of writing code, licked. Will start with one problem from all the Lerner Courses, that I still have to do. And another problem, I ask my friends to give me. This should prove for a promising start. If you, dear reader, have problems in Python that you’d like me, a budding Python programmer to solve, please mail them to me at jason at this domain. It’ll add to my pool of problems and give me plenty to practice. ...

July 27, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 019 - Python Iterators and Generators, Done!

Starting up with the last of the Lerner courses, I got. Iterators and Generators. Hopefully I get done with this and use the same intensity with actually writing code. What shape will that take and how will I write about it? I have no clue For now, notes follow. Notes ** Part 1, Iterators ** If we run the iter function on something and it comes back with an iterator object, then it’s iterable; I can iterate on it. Behind scenes in a for loop, Python does something similar. It asks if the object that has to be looped over is iterable with iter. And then keeps doing next with it to get the next result/item, until it comes across a StopIteration which lets it know, that the values are exhausted and it can stop looping. The for loop is a very thin shell, that asks the appropriate questions of the iterator. But it is always the iterator that determines, what exactly is returned. iterable vs iterator iterable means that it can be put into a “for” loop in Python things like strings, lists, dictionaries, sets, files and objects (that I will soon create) that implement that iterator protocol. it responds positively to the iter function’s question, Are you iterable? It returns an iterator object instead of raising errors (TypeErrors in this case) an iterator is the object returned by the iterable, the thing on which the next function is run. it could be the original object (the iterable) itself. it could also be a seperate object returned by the iterable. when the iterator object is exhausted, it returns StopIteration these are what give us the values. How do I make my objects iterable? By implementing the iterator protocol the object must respond to iter, by returning an iterator object it should respond to the next function with values it should raise a StopIteration error, when it’s done. Best to create a helper class, pass the data to it and return that as the iterator instance. helps with state, since I can then use the same object and iterate over it multiple times independantly. ** Part 2, Generators ** ...

July 27, 2020 · Mario Jason Braganza