The Right Ports

nmap is a very useful tool to check the open ports. Yeah, bad guys could use it too but you want to make sure the host you have exposed to the Internet has the minimal number of ports open. When I scan my own host that hosts this blog site like nmap hayato-iriumi.net, I get the following output.

Starting Nmap 7.80 ( https://nmap.org ) at 2021-09-23 18:27 PDT
Nmap scan report for hayato-iriumi.net (150.136.86.255)
Host is up (0.097s latency).
Not shown: 996 filtered ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https
8080/tcp open  http-proxy

I have the 4 ports open intentionally for my own management of my site. This makes me think what I should actually do down the road. I should close 22 and use a bastion to SSH into the host for management.

8080 is open for another management reason. Obviously, 80 is open for HTTP connection which redirects traffic to 443 (SSL, HTTPS). If you do nmap google.com, you can see port 80 and 443 are open to public as well.

Starting Nmap 7.80 ( https://nmap.org ) at 2021-09-23 18:28 PDT
Nmap scan report for google.com (142.250.69.206)
Host is up (0.026s latency).
Other addresses for google.com (not scanned): 2607:f8b0:400a:805::200e
rDNS record for 142.250.69.206: sea30s08-in-f14.1e100.net
Not shown: 998 filtered ports
PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  https

Here is the first paragraph of nmap man page. It tells you what it’s supposed to do.

Nmap (“Network Mapper”) is an open source tool for network exploration and security auditing. It was designed to rapidly scan large networks, although it works fine against single hosts. Nmap uses raw IP packets in novel ways to determine what hosts are available on the network, what services (application name and version) those hosts are offering, what operating systems (and OS versions) they are running, what type of packet filters/firewalls are in use, and dozens of other characteristics. While Nmap is commonly used for security audits, many systems and network administrators find it useful for routine tasks such as network inventory, managing service upgrade schedules, and monitoring host or service uptime.

man page for nmap is pretty big so there must be a lot we can do with this tool.

Tech Support Scam

I’m guessing whoever come to read my blog is quite technical. I’m unpleasantly surprised that tech support scam has been going on on a large scale against innocent old people. I can’t stand such injustice. I have been so into this YouTube channel by Jim Browning. He has amazing skills to track them down.

I never thought such scams could make millions but they do. When you see “Virus Detected!” kind of message with a phone number by merely accessing a website, please do not call that number. They are there to fraud and rip off money from you. Please do not get fooled by the scary sounds or the alert messages. They are all fake written in JavaScript and HTML.

I hope this spreads at least some awareness of the scam industry mainly going on in India.

New Stuff

I am using Visual Studio 2012 Preview 3.1 on Windows 11. I didn’t plan on it but I just installed them when I saw them available on my personal laptop. I wouldn’t do it to my work laptop but I don’t mind being bleeding edge on my personal machine.

I like new stuff. It’s been my nature for decades in my software engineer career. I believe it has been doing good to me. Being a software engineer, you always need to keep up with new technology. The technology I used to work with a decade or 2 ago is completely different from what I deal with today.

If you find it hard to do, software engineer might not be the career for you. If you find it fun to do, then you have a good chance to be a good software engineer.

I’m not saying new stuff is always better. I think balance is very important. Using everything new is not good and sticking with old way only is not good either. It’s a matter of balance.

This blog is a place where I explore new stuff and keep it so that I can come back to it if I forget and share it with the people all over the world.

map Function in Python

map function in Python is a convenient way to execute function for a collection. Let’s see an example that does not use map function.

class playground(unittest.TestCase):
    def pow(self, n):
        return n**n

    def test_pow(self):
        numbers = range(10)
        for number in numbers:
            result = self.pow(number)
            print(result)

Output:

1
1
4
27
256
3125
46656
823543
16777216
387420489

The example above just executes the pow function sequentially for every item in the integer list.

If you use a map function, the code becomes concise and easier to manage. It might be a little confusing but if you get used to it, it’s not too bad.

class playground(unittest.TestCase):
    def pow(self, n):
        return n**n

    def test_map(self):
        numbers = range(10)
        results = map(self.pow, numbers)
        print(list(results))

Output:

[1, 1, 4, 27, 256, 3125, 46656, 823543, 16777216, 387420489]

I didn’t know 0^0 was 1… I knew n^0 was always 1 but… Interesting. 🙂

How to Set Default User for WSL (Ubuntu)

I have Ubuntu for WSL (Windows Subsystem for Linux). I’m not sure how it happened, but when I started the terminal, it started to default to the root user. I wanted to default the user to the one that’s not the root user.

ubuntu config --default-user hiriumi

Make sure to run it either from the Windows command line or PowerShell. Next time when you open Ubuntu terminal, it goes straight to the user you specified.

Missed Demo for the Japanese Students I Gave Speech to

I had an opportunity to give a speech to students who are looking to become engineers in Japan last Friday. It was great to meet them though it was online. They seemed eager to learn what takes to be engineers. I was honored to give speech to them. They were also learning English, so this may be good for them.

Due to my unpreparedness on my side, I missed one demo. I was basically compiling Java code and decomplie it with IntelliJ. I would like to show how it can be done here in this blog for their view.

First, create a text file (helloworld.java) with the following code. It’s just a simple hello world program in Java.

public class helloworld {
    public static void main(String args[])
    {
        System.out.println("Hello World");
    }
}

Once you have the file, compile it like the following from your terminal (command line).

javac helloworld.java

The javac (Java compiler) compiles the text file to Java byte code (helloworld.class). You can execute the hello world program like the following.

java helloworld

Output:

Hello World

When you open helloworld.class file with IntelliJ, you can decompile it.

Decompilation is not really a useful technique anymore because of the current trend of open source but if the source code is closed but you want to learn how the Java program works, it’s still an interesting technique to use especially while you are learning how program works.

I believe JetBrain provides students with free license so you may be able to use the IDEs for free.

The reason why I could not find the helloworld.class file at the time of demo was because I was using WSL 2 on Windows. I had the file on the Linux side of the OS but I had forgotten to copy the file on the Windows side. I’m so sorry about it.

There was so much more I wanted to talk to everyone about but our time was limited. I wish all of you successful careers and bright future. 🙂

Cheapest Way to Blog with Your Own Domain

Most of the hosting services want you to buy domain and host your site there. As I was working on my blog site, I’ve learned how I could change DNS record to point to my free tier host on Oracle Cloud Infrastructure. I wanted to do it because iPage.com was too slow for me.

Then, I thought what if I could use a service that allows me to just buy domains and manage my own DNS records without any hosting and host my site on OCI’s free tier?

When I was watching Scott Hanselman‘s YouTube video, I noticed something. He was using DNSimple for his DNS management. So this is a site where you can buy domains and manage DNS records and SSL certs.

So I pay $6 every month for the service and I pay $16 every year for my domain. $6×12+$16=$88 My blog site is hosted at OCI’s free tier host, so it does not cost anything. So I can have my own blog with my domain name for $88 per year. I think it’s quite reasonable.

Of course, this method requires pretty good knowledge of DNS, Web Server and SSL but if you are an engineer or planning to be one, I’d highly recommend it.

zsh

I like z shell. z shell (zsh) is built on top of bash, so your bash script should run without any modification. Here is how you can install zsh.

sudo apt install zsh

Here is how you can make zsh your default shell.

sudo sh -c "echo $(which zsh) >> /etc/shells" && chsh -s $(which zsh)

You may be prompted to create ~/.zshrc (equivalent to ~/.bashrc) when you start your terminal with zsh.

Once you have zsh installed, it’s time to install oh-my-zsh. It’s another cool open source project that allows you to have cool prompt on your terminal.

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

We don’t stop here. To make your prompt even cooler especially for your git operations, we install p10k.

Install p10k manually.

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc

Close your terminal and restart it.

Now you get a prompt like the following. It doesn’t show the right glyphs because you don’t have the right fonts and set to be used on your terminal.

Let’s download and install Nerd Fonts. First, clone this repo.

git clone https://github.com/ryanoasis/nerd-fonts.git

It takes some time for the whole repo to be downloaded.

Install the fonts by running the script.

cd nerd-fonts
./install.sh FiraCode

Now change your font of your terminal profile to FiraCode Nerd Font Mono Regular and then run the following command.

p10k configure

If you run through the wizard, you get your cool prompt! 🙂

Mistake

As I was trying to migrate this blog over to a free tier host on OCI, I accidentally ssh’ed into the existing host and removed the wp-content directory, which removed all the images for this site. I am trying to restore it now.

Backing up Database for WordPress

To migrate your WordPress site to your own host on Cloud, you have to backup your database. Backing up database is a very simple process as long as your host has phpMyAdmin to manage your database.

  • Login to your phpMyAdmin.
  • Select the database for your WordPress blog.
  • Click Export and then simply click Go.
  • After a while, you get the entire database as a SQL file. That’s it for backing the data up!