Skip to content

2016

VMware, i3 and multiple monitors

For a while now I’ve been trying to set up VMware to work with multiple monitors, in a Linux guest. With some windowmanagers it works out of the box without any issue, such as with Unity. I never figured out how to do it with xmonad, and recently I switched to i3 just to try something new. The damn “Cycle multiple monitors” button didn’t work here either. When I tried it, a message popped up saying:

The virtual machine must have up-to-date VMware Tools installed and running.

ncat, a modern implementation of netcat

ncat is a utility that is like the UNIX cat command but for network connections. It’s based on the original netcat and comes with a couple of more modern features.

In this short post, we’ll go through a couple of examples to see exactly what uses this tool has. I’m currently using ncat version 7.01, in Ubuntu 16.04. ncat is a part of the nmap package in Ubuntu.

Split a file into a number of equal parts

As an example, we have a file named primary_data_file.txt that contains 616 lines of data. We want to split this into 4 files, with the equal amount of lines in each.

$ wc -l primary_data_file.txt 
616 primary_data_file.txt

The following command should do the trick:

split -da 1 -l $((`wc -l < primary_data_file.txt`/4)) primary_data_file.txt split_file --additional-suffix=".txt"

The option -da generates the suffixes of length 1, as well as using numeric suffixes instead of alphabetical.

The results after running the command are the following files:

$ wc -l split_file*
  154 split_file0.txt
  154 split_file1.txt
  154 split_file2.txt
  154 split_file3.txt
  616 total

Test if a port on a remote system is reachable

With telnet:

telnet webserver.example.com 80

With bash:

cat < /dev/tcp/webserver.example.com/80

Replace tcp with udp, depending on what you want.

With netcat:

nc webserver.example.com 80 &> /dev/null; echo $?

If the port is open, you will get an output of 0. If it’s closed, it’s a 1.