adamkdean

software engineering

Port scanning with Netcat

By Adam K Dean on

Netcat, or nc, is an excellent tool for linux. One thing it's great for is port scanning.

Let us say we want to scan for open ports from 1 to 1000, we can do that like so:

nc -n -z -w 1 192.168.1.2 1-1000

-n prevents DNS lookup. -z will prevent Netcat from receiving any data. -w 1 sets the timeout to 1 second.

You can also use -v to make it verbose, but this will obscure the visibility of successful attempts, which running it without shows.

An example output for the above command is:

Connection to 192.168.1.2 80 port [tcp/] succeeded!
Connection to 192.168.1.2 427 port [tcp/
] succeeded!
Connection to 192.168.1.2 515 port [tcp/*] succeeded!

So useful!

Count files in a directory in Linux

By Adam K Dean on

Count files in current directory with:

ls | wc -l

Or count files in a specific directory with:

ls /some/path | wc -l

Using exclamation marks in commit messages!

By Adam K Dean on

If you've ever been particularly excited by a recent packet of work you've done, and tried to show your excitement by putting an exclamation mark into the commit message, then you may have been met with this particular error:

git commit -m "I did some most excellent work!"
sh.exe": !": event not found

You have two ways around this. One most excellent way is to use single quotes:

git commit -m 'I did some most excellent work!'
[branch 123abc] I did some most excellent work!
1 file changed, 2 insertions(+)

Another way, if you require double quotes, is to add it onto the end with single quotes:

git commit -m "I did some most excellent work"'!'
[branch 123abc] I did some most excellent work!
1 file changed, 2 insertions(+)

Unfortunately, simply escaping the character will not work, you will just end up with \!.

Change filename case in git

By Adam K Dean on

Git is case-insensitive. So to change filename case in git, you have to jump through a (small) hoop.

git -f <source> <destination>

Example:

git -f src/helloworld.js src/HelloWorld.js

And that's it!

Install LESS highlighting in Sublime Text

By Adam K Dean on

Sublime Text doesn't come with LESS highlighting by default, but it's quite easy to install.

I've pulled the following from my previous blog post on how to install Zen Coding/Emmet in Sublime Text.

The first thing you want to do is open up Sublime Text. If you don't already have the package manager installed, then install it by bringing up the console Ctrl + ' and pasting in:

import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

Press enter and wait for that to install. Once complete, press Ctrl + Shift + P to bring up the command palette and type Install, press enter to select Package Control: Install package.

Once the menu appears, type LESS and select the first package.

Enjoy.