Monthly Archives: March 2022

Front End (Beginners): Check if an AJAX request is made

I created this little video to show how to use the Web Developer Tools to check if jQuery AJAX request is being made.

This is to help beginners in their journey learning to program Front End.

Please be aware that the page I used makes their own calls for marketing purposes. I cleared several times the history to show what is the real AJAX request we are doing.

Note: The recording program did not capture correctly the mouse position and this video has no sound.

The page I shown is:

https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_ajax

And some more info about jQuery .ajax method:

https://www.w3schools.com/jquery/ajax_ajax.asp

Normally you can try your HTML and JavaScript from your browser, opening the HTML file. However there are Security restrictions when it applies to AJAX requests or trying to access a local file from the browser.

You’ll need to run your JavaScript from an HTML page server from a Web Server. You can install apache if you use Linux, or WAMP if you use Windows or MAMP (Mac Apache MySQL PHP) if you use Mac or if you know how to you can create a Docker Container.

When you’re programming and your code does not trigger, pay attention to errors:

Top right, red circle, shows one error

News from the blog 2022-03-22

Support to Ukraine

I’m Catalan. In 1936 the fascist military leaded by franco raised in arms against the elected government of the Spanish Republic. The Italian and nazi German fascist in power bombed the Catalan population. Hundreds of thousands of innocent citizens were assassinated and millions of Catalan and Spaniards had to exile. The sons of those that were ruling with the dictator have been insisting in naming it a “civil war”, but it was the military lead by a fascist, revolting against the legitimate Republic and ending a democracy.

The dictatorship lasted until 1975, when the dictator died in the bed. The effects of the repression never abandoned Catalonia, and nowadays in Catalonia people is still detained by the Spanish police for talking the Catalan language in front of them, and our Parliament decisions are cancelled by the Spanish courts, for example to force the exit of a President of Catalonia that they didn’t like, or to force the Catalan schools to teach 25% of the time in Spanish attacking the Catalan teaching system.

During WW2 millions of Jews were mass murdered, also people from all the nations were assassinated.

Russian population suffered a lot also fighting the nazis.

Now we have to see how Russia’s army is invading Ukraine and murdering innocent citizens.

That’s horrible.

I know Engineers from Ukraine. Those guys were doing great building wealthy based on knowledge and working well for companies across the world. Now these people are being killed or Engineers, amongst all the brave population, are arming themselves to fight the invasion. Shells destroy beautiful cities and population are starving, and young soldiers from both sides will never be seen again by their mothers.

I wrote a small article on how to identify and block in the Ubuntu firewall the Ip’s from Russia and Belarus until Russia leaves Ukraine.

Let music play in solidarity with Ukraine. First is a Catalan group. Second is a famous Irish band in this epic song dedicated to the brave International Brigades, volunteers that fought the fascism in Spain and in Catalonia trying to make a better world.

The Blog

I’ve updated the SSL Certificate. The previous one I bought was issued for two years, and I renewed as it was due to expire.

I wrote a short article about how to update the SSL Certificates for Apache 2 in Ubuntu 20.04.

Articles

I published a small Python script to show the local datetime and the Unix Epoch Time.

Open Source

carleslibs

On the 6th of January I released carleslibs v.1.0.7

https://pypi.org/project/carleslibs/1.0.7/

The new version contains these improvements:

  • Modified OsUtils.get_total_and_free_space_in_gib() to return float instead of Integer.
  • Added HashUtils class with md5 for unicode Strings.
    • Produces the same as md5sum Linux tool.
  • Created FileUtils.create_folders() which creates all the subfolders in the path deep.
  • Unit Testing:
    • Added test_get_inodes_in_use_and_free() to test_osutils.py
    • Added two tests more to test_osutils.py
    • Added test for version.py
    • Tests for HashUtils class.

My books

Python 3 Exercises for Beginners

I have updated the book, offering solution to exercises 11.1, 11.2 (simple and encapsulated in a function) and I’ve created exercise 11.3.

If you purchased the book before, you can download any update for free.

Amazon AWS

I got an offer by a super editorial to publish my book Automating and Provisioning with Amazon Python 3 SDK boto3.

Honestly, my ego was flattered. It is a lot of reputation.

Although in the past I got an offer from another monstrously big editorial to publish world wide my book Python 3 Combat Guide and I also rejected, and an offer from a digital learning platform to create an interactive course from this same book.

I’ve rejected it again this time.

If you are curious, this is what I answered to them:

Hi XXXX,

I'm well, thank you. I hope you are doing well too.

Thanks for taking the time to explain your conditions to me.

I feel flattered by your editorial thinking about me. I respect your brand, as I mentioned, as I own several of your titles.

However, I have to refuse your offer.

Is not the first time an editor has offered to publish one or more of my books. For all over the world, with much higher economic expectations.

I'll tell you why I love being at LeanPub:

1- I own the rights. All of them.
2- I can publish updates, and my readers get them for free. As I add new materials, the value is maximized for my readers.
3- I get 80% of the royalties.
4- If a reader is not happy, they can return the book for 60 days.
5- I can create vouchers and give a discount to certain readers, or give for free to people that are poor and are trying to get a career in Engineering.

The community of readers are very honest, and I only got 2 returns. One of them I think was from an editorial that purchased the book, evaluated it, and they contacted me to publish it, and after I rejected they applied for the refund.

I teach classes, and I charge 125 EUR per hour. I can make much more by my side than the one time payment you offer. The compensation for the video seems really obsolete.

Also, I could be using Amazon self publishing, which also brings bigger margins than you.

So many thanks for your offer. I thought about it because of the reputation, but I already have a reputation. I've thousands of visits to my tech blog, and because of the higher royalties, even if I sell less books through LeanPub it is much more rewarding.

Thanks again and have a lovely day and rest of the week.


Best,
Carles

The provisioning in Amazon AWS through their SDK is a book I’m particularly proud, as it empowers the developers so much. And I provide source code so they can go from zero to hero, in a moment. Amazon should provide a project sample as I do, not difficult to follow documentation.

Teaching / Mentoring

As I was requested, I’ve been offering advice and having virtual coffees with some people that recently started their journey to become Software Engineers and wanted some guidance and advice.

It has been great seeing people putting passion and studying hard to make a better future for themselves and for their families.

I’ll probably add to the blog more contents for beginners, although it will continue being a blog dedicated to extreme IT, and to super cool Engineering skills and troubleshooting.

For my regular students I have a discord space where we can talk and they can meet new friends studying or working in Engineering.

Free Resources

This github link provides many free books in multiple languages:

https://github.com/EbookFoundation/free-programming-books

Tricks

Zoom can zoom the view. So if they are sharing their screen, and font is too small, you can give a relax to your eyes by using Zoom’s zoom feature. It is located in View.

My health

After being in the hospital in December 2021, with risk for my life, and after my incredible recuperation, I’ve got the good news that I don’t need anymore 2 of the 3 medicines I was taking in a daily basis. It looks well through a completely recovery thanks to my discipline, doing sport every day several times, and the fantastic Catalan doctors that are supporting me so well.

Since they found what was failing in me, and after the emergency treatments I started to sleep really well. All night. That’s a privilege that I didn’t have for long long time.

Humor

Sad but true history. How many super talented Engineers have been hired and then they were given a shitty laptop/workstation super slow? That happened to me when I was hired by Volkswagen IT: gedas. I was creating projects for very big companies and I calculated that I was wasting 2 hours of my time compiling. The computer did not had enough RAM and was using swap.

JavaScript fun (or not)

Yes, this works like this.

You can try yourself:

<html>
<body>
<script>
    console.log("11" + 1)
    console.log("11" - 1)
</script>
</body>
</html>

As you can see if you open the Browser Developer tools (in Linux and Windows press F12 key):

Firsts steps programming in Python 3 with PyCharm and Git

This is a very simple guide for beginners, to benefit from using this amazing Python IDE with Git.

You may think that it’s a bit difficult and why you should use it. The first reason I would tell is because it marks the errors, not just syntax errors also if you have typos or you forgot an import or you forgot to declare a variable, has autocomplete, will mark when you don’t follow standards, etc… If you want to be a professional, this is the tool that most Python professional developers and companies use.

Go to Jetbrains page and from there select Developer Tools and PyCharm.

You can use this url to go directly:

https://www.jetbrains.com/pycharm/

PyCharm Community Edition is completely free.

If you don’t have it, create an account in Gitlab. I recommend you to use Gitlab over Github.

Before continuing you’ll have to validate your account by clicking the email that Gitlab sent you.

Create a New project, by pressing the blue button with this label.

Choose Create blank project.

If you select Public everybody will be able to see your code, I recommend you to start with a Private project.

Let checked Initialize repository with a README as this will save you plenty of time and will allow you to start working immediately.

The project will be created for you.

Hit the Clone blue button and it will provide two methods to clone your git repository. You will copy the Clone with HTTPS url.

There are different ways to clone a new project.

Assuming you already have one opened go to Main Menu > Git > Clone

In the URL field paste the URL you copied from Gitlab, in my case:

https://gitlab.com/carles.mateo/carles-mateo-demo-project.git

And press the blue botton Clone.

If you don’t have Git installed, PyCharm will tell you in red, and will allow you to install it for you. It is a very convenient way to install it, specially if you use Windows.

In Ubuntu or Debian Linux installing git is so easy as typing from the Terminal:

sudo apt install git

If it’s your first time PyCharm will ask you for your credentials in Gitlab, so your username or email, and your password.

As it is you own new project and it’s empty, you can trust it. Hit Trust Project.

A window with tips will appear, you can close it.

As you see your project is empty. Only has a the default README.md file created by Gitlab.

Creating new Python files

On the top left, over the name of your project folder press with the Right button of the mouse and select New > Python File

Enter the name of the file, I choose helloworld and press Enter.

You will be asked if you want to add automatically the file to Git. This refers to your local Git repository. Say Yes and you will see the file changing from color Red, which means it is not added to the repository to Green. Green means that is added, but has never been committed.

Just add this line to helloworld.py

print("Hello World")

Note: I made a typo and I wrote “helloworl.py” instead of “helloworld.py”, I will show how to fix this later.

Now, press over the file name over the top left, with the Right button of the mouse, and select Run helloworl (In your case will be Run helloword)

Note: To be able to run a Python program, you need to have Python installed.

Note2: Do not start the name of your file by test as PyCharm will consider that you are writing Unit Testing Code, and will not show the option to run the code, but to run with pytest (if you have pytest framework installed).

And you see on the bottom how it worked and printed “Hello World”.

To rename the file you’ll click over it with the Right button of the mouse and select Refactor > Rename

Type the correct name, in my case “helloworld.py” and for the Scope select: Current File.

PyCharm is so powerful that can search for your entire project to see if other files are using that file and will update the code to reflect the file name change. By indicating Scope: Current File we are telling that the change affects only to this file, and by not marking Search for references and not marking Search in comments and strings you are indicating to PyCharm that it should not search in code and comments to update them with the new file. This option is really useful when you get more confident with programming.

Perfect. Now you want to commit the file to the repository and Push.

The first time PyCharm will ask you how people will know you, that is, your visible name in the Git History of Commits, and your email. You can mark to use these properties locally. This is basically because Git needs to know how to identify you. Consider that Git was created to work with Teams, so everybody should know who made what. Add your friendly name, like “Carles Mateo” and your email. I recommend you to check to use this info for Git globally (all the projects in your computer).

When you commit you’re expected to provide a Commit Message. As Git is used by teams, to work on the same code, try to explain briefly what your changes consisted on.

If you press Commit, you will see how helloworld.py is no longer in color green, now is black. This means that the file is up to date respect our local Git.

Go to the Main Menu and select Git > Push.

You’ll see a message in the bottom indicating that your code has been pushed to the repository.

Now, you can refresh your browser, and you’ll see the changes in Gitlab:

PyCharm vs VSCode

I got asked what are the advantage from PyCharm respect VSCode.

I may refer to this excellent comparison:

While VSCode has some great support for Python coding with the ‘Python’ plugin by Microsoft, PyCharm is truly designed for Python development and it shows.

https://tangenttechnologies.ca/blog/pycharm-vs-vscode/

https://tangenttechnologies.ca/blog/pycharm-vs-vscode/

Renewing a SSL Certificate for Apache2 in Ubuntu 20.04

First you have to generate a new csr and key files.

It is not recommended to reuse your old CSR file.

openssl req -new -newkey rsa:2048 -nodes -keyout blog_carles_mateo_com_2022.key -out blog_carlesmateo_com_2022.csr

As you can see I used the name of the domain and the year for the new files to be generated to easily distinguish them.

When you’re asked for the password, in the additional fields, keep that password safe in case you need the Cert to be reissued to you.

You’ll need to submit the CSR file to your SSL provider. They will return you the CRT and the CA-BUNDLE files.

Edit your Apache config file for the SSL site.

For example:

/etc/apache2/sites-enabled/11-https-blog-carlesmateo-com.conf

Your conf file will look similar to this:

<VirtualHost *:443>
	ServerAdmin webmaster@yourdomain.cat

	DocumentRoot /opt/sites/www/blog.carlesmateo.com
	ServerName blog.carlesmateo.com
        SSLEngine on
        SSLCertificateFile /opt/sites/certs/2022/blog_carlesmateo_com_2022.crt
        SSLCertificateKeyFile /opt/sites/certs/2022/blog_carlesmateo_com_2022.key
        SSLCertificateChainFile /opt/sites/certs/2022/blog_carlesmateo_com_2022.ca-bundle
...

Before restarting Apache2, test the configuration for syntax errors with:

apache2ctl -t

If all is good, restart your Web Server with:

service apache2 restart

With a browser, verify that the information of the domain is right. I recommend you to check in Firefox and Chrome at least.

A simple Python script to get the date and time in Unix Epoch and in local time

The Unix Epoch is the time, in seconds, that has passed since 1970-01-01 00:00:00 UTC.

#!/usr/bin/env python3

#
# Date time methods
#
# Author: Carles Mateo
# Creation Date: 2019-11-20 17:23 IST
# Description: Class to return Date, datetime, Unix EPOCH timestamp
#

import datetime
import time


class DateTimeUtils:

    def get_unix_epoch(self):
        """
        Will return the EPOCH Time. For convenience is returned as String
        :return:
        """
        s_now_epoch = str(int(time.time()))

        return s_now_epoch

    def get_datetime(self, b_milliseconds=False):
        """
        Return the datetime with miliseconds in format YYYY-MM-DD HH:MM:SS.xxxxx
        or without milliseconds as YYYY-MM-DD HH:MM:SS"""
        if b_milliseconds is True:
            s_now = str(datetime.datetime.now())
        else:
            s_now = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

        return s_now


def main():
    o_datetime = DateTimeUtils()
    s_now_epoch = o_datetime.get_unix_epoch()
    s_now_date = o_datetime.get_datetime()

    print(s_now_epoch)
    print(s_now_date)


main()

You can also get the code from:

https://gitlab.com/carles.mateo/blog.carlesmateo.com-source-code/

Blocking Russian and Belarus IP Addresses in Ubuntu’s Firewall

Last update: 2022-08-21

Me, as everybody in the civilized world, I’m shocked by the brutal invasion of Ukraine by Russia.

I’ve known brilliant IT Ukrainian Engineers and I have known how they have been helping companies around the world with their coding skills.

Me as everybody else have been receiving attacks from Russian and Belarus (and China) Ip Addresses in a daily basis for years, but I only blocked on the firewall the offending Ips.

But after the Russian invasion of Ukraine and the shelling over cities, and the murder of innocent people, families… not talking about the craziness of attacking the biggest nuclear power plant in Europe, I think that’s enough.

I know it can be argued that if the Russian population, which is not guilty of the decisions of their dictator president, are isolated from Internet they will be more alone. But I think that people that want peace, need to do something to set it clear that we don’t want anything to do with dictators that do not respect basic Human Rights.

Must say I have very nice Russian friends that are totally against the Russian invasion of Ukraine.

And obviously it doesn’t look like that Russian president is going to stop there. It looks to me like again, another crazy dictator is trying to invade Europe and enslave their nations. Also the repression against their own Russian population and the prosecution of Free of Speech, are unacceptable. And as a Catalan I know about this.

As Engineer, the only thing I can do is speak up and say No. This is bad. My way of doing that, is contributing to let the Russians know that the rest of the world do not approve invasions, violence and repression. And I’m adding my blog to the list of services that will not work in Russia and in Belarus.

I’ll be blocking in the Firewall any Russian and Belarus Ip Address I get to know until they leave Ukraine.

And I’ll share with you how you can do the same, and the Ip ranges that I found.

How to know if an IP belongs to Russia or Belarus

There are geographic databases that quickly will tell you.

But if you want to do it by yourself, in Linux you can do like this:

whois -a 94.231.154.121

In this case the IP that visited my blog belong to an ISP (Internet Service Provider). Their range is 94.231.144.0 to 94.231.159.255.

That range is the equivalent to 16 class C (or a mask /24 or in other words, 256 addresses):

  1. 94.231.144.0/24
  2. 94.231.145.0/24
  3. 94.231.146.0/24
  4. 94.231.147.0/24
  5. 94.231.148.0/24
  6. 94.231.149.0/24
  7. 94.231.150.0/24
  8. 94.231.151.0/24
  9. 94.231.152.0/24
  10. 94.231.153.0/24
  11. 94.231.154.0/24
  12. 94.231.155.0/24
  13. 94.231.156.0/24
  14. 94.231.157.0/24
  15. 94.231.158.0/24
  16. 94.231.159.0/24

These 16 class C /24, can be expressed as 8 /23, or 4 /22 or 2 /21 or one /20.

It is not always possible to use a mask for all the Ip’s of a provider, as they may have an even distribution, so in case of doubt you can use the route listed by whois for the ip you queried.

In this case I can use 94.231.144.0/20 so, 4,096 IP Addresses. I’m going to block them:

sudo ufw insert 1 deny from 94.231.144.0/20 to any

I’m going to block 2,097,152 of IP Addresses assigned to Russia in four ranges of 512K:

ufw insert 1 deny from 5.136.0.0/13 to any
ufw insert 1 deny from 95.24.0.0/13 to any
ufw insert 1 deny from 176.208.0.0/13 to any
ufw insert 1 deny from 178.64.0.0/13 to any

And few more blocks of 64K, 32K, 16K, 8K, 4K, 1K, 2K, 512 and 256 (/24) IP Addresses sorted, that connected to the blog:

ufw insert 1 deny from 5.18.0.0/16 to any
ufw insert 1 deny from 37.192.0.0/16 to any
ufw insert 1 deny from 109.252.0.0/16 to any
ufw insert 1 deny from 128.71.0.0/16 to any
ufw insert 1 deny from 194.220.0.0/16 to any
ufw insert 1 deny from 92.101.0.0/17 to any
ufw insert 1 deny from 92.255.128.0/17 to any
ufw insert 1 deny from 178.154.128.0/17 to any
ufw insert 1 deny from 37.9.64.0/18 to any
ufw insert 1 deny from 93.100.64.0/18 to any
ufw insert 1 deny from 93.100.128.0/18 to any
ufw insert 1 deny from 93.124.64.0/18 to any
ufw insert 1 deny from 141.8.128.0/18 to any
ufw insert 1 deny from 46.3.160.0/19 to any
ufw insert 1 deny from 46.38.96.0/19 to any
ufw insert 1 deny from 85.174.192.0/19 to any
ufw insert 1 deny from 85.234.32.0/19 to any
ufw insert 1 deny from 90.188.224.0/19 to any
ufw insert 1 deny from 94.242.0.0/19 to any
ufw insert 1 deny from 37.9.0.0/20 to any
ufw insert 1 deny from 37.9.32.0/20 to any
ufw insert 1 deny from 37.9.144.0/20 to any
ufw insert 1 deny from 46.148.192.0/20 to any
ufw insert 1 deny from 77.245.208.0/20 to any
ufw insert 1 deny from 79.110.64.0/20 to any
ufw insert 1 deny from 93.182.16.0/20 to any
ufw insert 1 deny from 95.152.32.0/20 to any
ufw insert 1 deny from 95.152.48.0/20 to any
ufw insert 1 deny from 109.168.224.0/20 to any
ufw insert 1 deny from 217.25.224.0/20 to any
ufw insert 1 deny from 217.114.144.0/20 to any
ufw insert 1 deny from 37.9.48.0/21 to any
ufw insert 1 deny from 37.9.128.0/21 to any
ufw insert 1 deny from 37.9.240.0/21 to any
ufw insert 1 deny from 85.202.0.0/21 to any
ufw insert 1 deny from 90.151.136.0/21 to any
ufw insert 1 deny from 95.72.24.0/21 to any
ufw insert 1 deny from 95.72.104.0/21 to any
ufw insert 1 deny from 195.133.152.0/21 to any
ufw insert 1 deny from 5.164.228.0/22 to any
ufw insert 1 deny from 5.164.248.0/22 to any
ufw insert 1 deny from 37.113.12.0/22 to any
ufw insert 1 deny from 37.113.32.0/22 to any
ufw insert 1 deny from 37.113.44.0/22 to any
ufw insert 1 deny from 37.113.52.0/22 to any
ufw insert 1 deny from 37.113.60.0/22 to any
ufw insert 1 deny from 37.113.136.0/22 to any
ufw insert 1 deny from 46.146.4.0/22 to any
ufw insert 1 deny from 62.217.188.0/22 to any
ufw insert 1 deny from 79.173.88.0/22 to any
ufw insert 1 deny from 91.204.148.0/22 to any
ufw insert 1 deny from 91.210.4.0/22 to any
ufw insert 1 deny from 91.219.56.0/22 to any
ufw insert 1 deny from 94.181.44.0/22 to any
ufw insert 1 deny from 94.181.164.0/22 to any
ufw insert 1 deny from 95.79.88.0/22 to any
ufw insert 1 deny from 95.170.152.0/22 to any
ufw insert 1 deny from 109.194.240.0/22 to any
ufw insert 1 deny from 109.194.244.0/22 to any
ufw insert 1 deny from 109.194.252.0/22 to any
ufw insert 1 deny from 178.17.180.0/22 to any
ufw insert 1 deny from 178.76.220.0/22 to any
ufw insert 1 deny from 195.133.16.0/22 to any
ufw insert 1 deny from 212.192.244.0/22 to any
ufw insert 1 deny from 212.193.184.0/22 to any
ufw insert 1 deny from 5.188.158.0/23 to any
ufw insert 1 deny from 31.173.242.0/23 to any
ufw insert 1 deny from 37.113.56.0/23 to any
ufw insert 1 deny from 46.148.234.0/23 to any
ufw insert 1 deny from 46.242.8.0/23 to any
ufw insert 1 deny from 80.95.44.0/23 to any
ufw insert 1 deny from 81.9.126.0/23 to any
ufw insert 1 deny from 83.220.238.0/23 to any
ufw insert 1 deny from 90.154.72.0/23 to any
ufw insert 1 deny from 93.159.230.0/23 to any
ufw insert 1 deny from 188.124.46.0/23 to any
ufw insert 1 deny from 188.130.136.0/23 to any
ufw insert 1 deny from 212.109.196.0/23 to any
ufw insert 1 deny from 5.188.170.0/24 to any
ufw insert 1 deny from 5.188.211.0/24 to any
ufw insert 1 deny from 37.113.58.0/24 to any
ufw insert 1 deny from 46.8.155.0/24 to any
ufw insert 1 deny from 46.8.156.0/24 to any
ufw insert 1 deny from 46.8.222.0/24 to any
ufw insert 1 deny from 46.161.48.0/24 to any
ufw insert 1 deny from 62.76.153.0/24 to any
ufw insert 1 deny from 62.113.118.0/24 to any
ufw insert 1 deny from 83.220.227.0/24 to any
ufw insert 1 deny from 91.230.107.0/24 to any
ufw insert 1 deny from 91.241.19.0/24 to any
ufw insert 1 deny from 91.243.44.0/24 to any
ufw insert 1 deny from 91.244.183.0/24 to any
ufw insert 1 deny from 94.103.80.0/24 to any
ufw insert 1 deny from 94.103.81.0/24 to any
ufw insert 1 deny from 94.103.82.0/24 to any
ufw insert 1 deny from 94.103.83.0/24 to any
ufw insert 1 deny from 94.103.84.0/24 to any
ufw insert 1 deny from 94.103.85.0/24 to any
ufw insert 1 deny from 94.103.86.0/24 to any
ufw insert 1 deny from 94.103.87.0/24 to any
ufw insert 1 deny from 94.103.88.0/24 to any
ufw insert 1 deny from 94.103.89.0/24 to any
ufw insert 1 deny from 94.103.90.0/24 to any
ufw insert 1 deny from 94.103.91.0/24 to any
ufw insert 1 deny from 94.103.92.0/24 to any
ufw insert 1 deny from 94.103.93.0/24 to any
ufw insert 1 deny from 94.103.94.0/24 to any
ufw insert 1 deny from 94.103.95.0/24 to any
ufw insert 1 deny from 94.140.138.0/24 to any
ufw insert 1 deny from 109.107.180.0/24 to any
ufw insert 1 deny from 109.194.21.0/24 to any
ufw insert 1 deny from 109.248.128.0/24 to any
ufw insert 1 deny from 176.113.115.0/24 to any
ufw insert 1 deny from 178.20.43.0/24 to any
ufw insert 1 deny from 178.176.214.0/24 to any
ufw insert 1 deny from 178.204.251.0/24 to any
ufw insert 1 deny from 179.60.149.0/24 to any
ufw insert 1 deny from 185.7.214.0/24 to any
ufw insert 1 deny from 185.9.187.0/24 to any
ufw insert 1 deny from 185.63.61.0/24 to any
ufw insert 1 deny from 185.76.147.0/24 to any
ufw insert 1 deny from 185.88.102.0/24 to any
ufw insert 1 deny from 192.166.119.0/24 to any
ufw insert 1 deny from 193.218.118.0/24 to any
ufw insert 1 deny from 194.87.218.0/24 to any
ufw insert 1 deny from 194.186.207.0/24 to any
ufw insert 1 deny from 194.190.90.0/24 to any
ufw insert 1 deny from 213.135.156.0/24 to any

Also, I have these additional assorted Russian IP Addresses Ranges, which also connected to the blog:

ufw insert 1 deny from 94.140.134.0/24 to any
ufw insert 1 deny from 5.167.48.0/22 to any
ufw insert 1 deny from 188.225.85.0/24 to any

ufw insert 1 deny from 188.170.175.0/24 to any
ufw insert 1 deny from 93.124.32.0/20 to any
ufw insert 1 deny from 213.226.123.0/24 to any
ufw insert 1 deny from 128.69.80.0/24 to any

ufw insert 1 deny from 176.226.128.0/19 to any
ufw insert 1 deny from 89.208.28.0/23 to any
ufw insert 1 deny from 88.201.128.0/20 to any

ufw insert 1 deny from 94.245.135.0/24 to any

ufw insert 1 deny from 95.161.221.0/24 to any

ufw insert 1 deny from 95.84.192.0/18 to any

ufw insert 1 deny from 92.100.0.0/16 to any

ufw insert 1 deny from 88.147.152.0/24 to any

ufw insert 1 deny from 194.190.179.0/24 to any

ufw insert 1 deny from 178.237.248.0/22 to any

ufw insert 1 deny from 94.25.128.0/17 to any

ufw insert 1 deny from 37.20.128.0/17 to any

ufw insert 1 deny from 85.113.128.0/21 to any

ufw insert 1 deny from 45.9.20.0/24 to any

ufw insert 1 deny from 91.225.25.0/24 to any
ufw insert 1 deny from 5.164.136.0/22 to any

ufw insert 1 deny from 31.210.223.0/24 to any

ufw insert 1 deny from 5.175.96.0/20 to any

ufw insert 1 deny from 149.255.24.0/21 to any

ufw insert 1 deny from 109.174.112.0/22 to any

ufw insert 1 deny from 188.127.242.0/24 to any

ufw insert 1 deny from 92.248.220.0/22 to any

ufw insert 1 deny from 178.155.4.0/24 to any
ufw insert 1 deny from 79.173.80.0/22 to any

ufw insert 1 deny from 188.254.0.0/17 to any

ufw insert 1 deny from 193.106.191.0/24 to any

ufw insert 1 deny from 95.55.0.0/17 to any
ufw insert 1 deny from 217.25.208.0/20 to any
ufw insert 1 deny from 31.132.232.0/21 to any
ufw insert 1 deny from 93.92.192.0/21 to any
ufw insert 1 deny from 95.32.128.0/23 to any
ufw insert 1 deny from 188.233.52.0/22 to any
ufw insert 1 deny from 87.244.6.0/24 to any
ufw insert 1 deny from 91.232.108.0/22 to any
ufw insert 1 deny from 84.42.32.0/19 to any
ufw insert 1 deny from 46.0.52.0/22 to any
ufw insert 1 deny from 79.133.112.0/21 to any
ufw insert 1 deny from 178.184.0.0/17 to any
ufw insert 1 deny from 178.34.148.0/22 to any
ufw insert 1 deny from 94.19.192.0/18 to any
ufw insert 1 deny from 77.223.68.0/22 to any
ufw insert 1 deny from 46.138.0.0/16 to any
ufw insert 1 deny from 37.110.0.0/17 to any
ufw insert 1 deny from 78.132.232.0/21 to any
ufw insert 1 deny from 188.255.0.0/17 to any
ufw insert 1 deny from 212.193.138.0/24 to any
ufw insert 1 deny from 46.0.203.0/24 to any
ufw insert 1 deny from 213.234.222.0/24 to any
ufw insert 1 deny from 94.180.140.0/22 to any

ufw insert 1 deny from 176.119.140.0/24 to any
ufw insert 1 deny from 94.181.152.0/22 to any
ufw insert 1 deny from 109.248.14.0/24 to any
ufw insert 1 deny from 109.248.129.0/24 to any
ufw insert 1 deny from 109.248.55.0/24 to any
ufw insert 1 deny from 45.135.33.0/24 to any

ufw insert 1 deny from 5.8.10.0/24 to any
ufw insert 1 deny from 80.66.65.0/24 to any
ufw insert 1 deny from 45.146.164.0/22 to any
ufw insert 1 deny from 31.129.3.0/24 to any
ufw insert 1 deny from 46.235.64.0/23 to any
ufw insert 1 deny from 93.187.184.0/21 to any
ufw insert 1 deny from 77.37.192.0/18 to any
ufw insert 1 deny from 78.153.130.0/24 to any
ufw insert 1 deny from 195.68.128.0/18 to any
ufw insert 1 deny from 79.139.128.0/17 to any

ufw insert 1 deny from 62.233.50.0/24 to any
ufw insert 1 deny from 194.79.45.0/24 to any
ufw insert 1 deny from 83.69.224.0/19 to any
ufw insert 1 deny from 77.35.0.0/18 to any
ufw insert 1 deny from 62.113.115.0/24 to any
ufw insert 1 deny from 136.169.255.0/24 to any
ufw insert 1 deny from 136.169.254.0/24 to any
ufw insert 1 deny from 136.169.253.0/24 to any
ufw insert 1 deny from 136.169.252.0/24 to any
ufw insert 1 deny from 136.169.251.0/24 to any
ufw insert 1 deny from 136.169.250.0/24 to any
ufw insert 1 deny from 136.169.249.0/24 to any
ufw insert 1 deny from 136.169.248.0/24 to any
ufw insert 1 deny from 136.169.247.0/24 to any
ufw insert 1 deny from 136.169.246.0/24 to any
ufw insert 1 deny from 136.169.245.0/24 to any
ufw insert 1 deny from 136.169.244.0/24 to any
ufw insert 1 deny from 136.169.243.0/24 to any
ufw insert 1 deny from 136.169.242.0/24 to any
ufw insert 1 deny from 136.169.241.0/24 to any
ufw insert 1 deny from 136.169.240.0/24 to any
ufw insert 1 deny from 5.228.0.0/16 to any
ufw insert 1 deny from 176.59.64.0/19 to any
ufw insert 1 deny from 80.82.60.0/22 to any
ufw insert 1 deny from 37.204.0.0/16 to any
ufw insert 1 deny from 188.32.0.0/16 to any
ufw insert 1 deny from 213.234.251.0/24 to any
ufw insert 1 deny from 77.35.128.0/18 to any
ufw insert 1 deny from 46.72.192.0/19 to any
ufw insert 1 deny from 91.239.85.0/24 to any
ufw insert 1 deny from 178.176.64.0/19 to any
ufw insert 1 deny from 37.252.224.0/19 to any

ufw insert 1 deny from 178.140.0.0/16 to any
ufw insert 1 deny from 83.220.240.0/20 to any
ufw insert 1 deny from 109.237.100.0/22 to any
ufw insert 1 deny from 89.185.85.0/24 to any
ufw insert 1 deny from 195.91.168.0/24 to any
ufw insert 1 deny from 95.84.32.0/19 to any
ufw insert 1 deny from 46.182.129.0/24 to any
ufw insert 1 deny from 46.182.130.0/24 to any
ufw insert 1 deny from 46.182.131.0/24 to any
ufw insert 1 deny from 46.182.132.0/24 to any
ufw insert 1 deny from 46.182.133.0/24 to any
ufw insert 1 deny from 46.182.134.0/24 to any
ufw insert 1 deny from 46.182.135.0/24 to any
ufw insert 1 deny from 136.169.128.0/18 to any
ufw insert 1 deny from 46.146.0.0/18 to any
ufw insert 1 deny from 46.146.64.0/19 to any
ufw insert 1 deny from 5.165.128.0/21 to any
ufw insert 1 deny from 78.29.96.0/19 to any
ufw insert 1 deny from 95.105.96.0/19 to any
ufw insert 1 deny from 95.104.192.0/21 to any
ufw insert 1 deny from 94.232.40.0/21 to any
ufw insert 1 deny from 77.35.224.0/19 to any
ufw insert 1 deny from 46.235.66.0/23 to any
ufw insert 1 deny from 178.45.248.0/21 to any
ufw insert 1 deny from 213.87.128.0/20 to any
ufw insert 1 deny from 185.60.44.0/22 to any
ufw insert 1 deny from 5.188.62.0/24 to any

ufw insert 1 deny from 93.124.48.0/20 to any
ufw insert 1 deny from 194.24.240.0/24 to any
ufw insert 1 deny from 188.187.68.0/22 to any
ufw insert 1 deny from 94.45.4.0/22 to any
ufw insert 1 deny from 88.83.192.0/19 to any
ufw insert 1 deny from 94.180.172.0/22 to any
ufw insert 1 deny from 213.108.0.0/22 to any
ufw insert 1 deny from 2.92.0.0/16 to any
ufw insert 1 deny from 176.114.64.0/24 to any
ufw insert 1 deny from 88.147.153.0/24 to any
ufw insert 1 deny from 109.248.138.0/23 to any

ufw insert 1 deny from 46.3.196.0/24 to any
ufw insert 1 deny from 212.248.0.0/17 to any
ufw insert 1 deny from 88.147.173.0/24 to any
ufw insert 1 deny from 95.79.132.0/22 to any
ufw insert 1 deny from 46.235.68.0/23 to any
ufw insert 1 deny from 5.227.0.0/17 to any
ufw insert 1 deny from 178.204.0.0/15 to any

ufw insert 1 deny from 94.181.184.0/22 to any
ufw insert 1 deny from 94.181.176.0/20 to any
ufw insert 1 deny from 188.130.129.0/24 to any

# Not 100% this one is russian
ufw insert 1 deny from 85.192.63.0/24 to any

ufw insert 1 deny from 85.192.63.0/24 to any
ufw insert 1 deny from 83.220.236.0/22 to any
ufw insert 1 deny from 95.110.32.0/19 to any
ufw insert 1 deny from 83.149.21.0/24 to any

I’ve identified this range of 32K, 8K IP Addresses and a class C from Belarus:

ufw insert 1 deny from 178.154.0.0/17 to any
ufw insert 1 deny from 134.17.160.0/19 to any
ufw insert 1 deny from 86.57.147.0/24 to any

If you need a CIDR / subnet calculator this is great: https://www.calculator.net/ip-subnet-calculator.html

I write all these ranges in a script, so I can apply to all my Servers, and so I can remove them from the Firewalls when Russia and Belarus leave Ukraine.