Tuesday, 5 January 2016

Paste minus formatting

We're all faced with situations of copying from one formatting editor to another formatting editor. It's usually a pain to make sure that the formatting in the previous editor is not applied in the new one because we may only be interested in the content and not the formatting.

Let's take an example. Say you have a piece of code available in an eclipse editor. For the readers from non-programming background, it's one of the popular editors used usually for Java. You are creating a document using MS Word for your fellow team members that refers to this piece of code. Let's assume you are following a specific style for the code blocks inserted in your document. But when you copy paste the code from eclipse, the formatting is carried forward and is used in the Word document. This is a useful feature but in some cases like the one described above, it causes problems.

It becomes cumbersome to manually remove the formatting and bring it to the format you desire. In such situations, a non formatting text editor comes in handy. Notepad and Notepad++ on Windows can be utilized for this purpose. Notepad++ is not entirely a non formatting editor but can be used for temporarily pasting the text. So the sequence would be as follows

source -> non-formatting editor ->destination

and et voila you're done. Now you can go ahead and apply the required formatting :)

Saturday, 14 November 2015

Trick to find the IP of Raspberry Pi with no display

Recently I had an opportunity of working on a project that required Raspberry Pi. It was incredible to see such a powerful device fit in such a small box. All you need to use Pi as a regular computer is a display, a USB keyboard and a USB mouse. It is 2 to 3 times powerful than the computer I have at home that I purchased about 10 years back and costs only 6% of the computer's price! Obviously it's excluding the display, keyboard and mouse that's required for the Pi, yet it is very cheap. Anyways, so I got the SD card ready with Raspbian and got it started. Then I plugged in the LAN cable so that I could remotely access it. But there was a problem. I did not know its IP. And to know the IP, I needed to get access to its console. So then I searched google for options to get the video output for Pi and I found many articles like this and this.

I had a colleague who had an hdmi monitor, so I used it to get the console and changed the IP to static IP and got cracking. After some days, I had to make use of another SD card due to some reasons and I was stuck in the same situation again. This time around, that colleague of mine was stuck in a really tight situation with his project and I did not feel like bothering him. So I thought of finding an alternative and I did not want to invest in any extra hardware. I thought that knowing the IP is all I need and how hard could it be. So I started searching for ways to get all the IP in a LAN (yeah I am a little new to networking) and found this. At first I had thought of just iterating through all of the IPs obtained and try my luck. But then I thought there should be a better way. And yes there was a better way. I just needed to know the IP of my Pi. So then I disconnected my Pi from the LAN and ran the command and got the IPs of all the existing computers/devices.

My LAN's addresses were in the range 10.73.73.*. So I ran the following command
nmap -sP 10.73.73.* | tee allIPs-Pi.txt

Following are the contents of allIPs-Pi.txt
Starting Nmap 5.21 ( http://nmap.org ) at 2015-11-14 12:21 IST
Nmap scan report for 10.73.73.8
Host is up (0.00078s latency).
Nmap scan report for 10.73.73.9
Host is up (0.00049s latency).
Nmap scan report for 10.73.73.17
Host is up (0.00077s latency).
Nmap scan report for 10.73.73.18
Host is up (0.00075s latency).
Nmap scan report for 10.73.73.20
Host is up (0.00023s latency).
Nmap scan report for 10.73.73.22
Host is up (0.00028s latency).
Nmap scan report for 10.73.73.28
Host is up (0.0011s latency).
Nmap scan report for 10.73.73.50
Host is up (0.00077s latency).
Nmap scan report for 10.73.73.150
Host is up (0.00045s latency).
Nmap scan report for 10.73.73.155
Host is up (0.00023s latency).
Nmap scan report for 10.73.73.162
Host is up (0.0013s latency).
Nmap scan report for 10.73.73.163
Host is up (0.00046s latency).
Nmap scan report for 10.73.73.164
Host is up (0.00045s latency).
Nmap scan report for 10.73.73.175
Host is up (0.0011s latency).
Nmap scan report for 10.73.73.177
Host is up (0.00030s latency).
Nmap scan report for 10.73.73.180
Host is up (0.00097s latency).
Nmap scan report for 10.73.73.181
Host is up (0.00042s latency).
Nmap scan report for 10.73.73.187
Host is up (0.000059s latency).
Nmap scan report for 10.73.73.193
Host is up (0.0012s latency).
Nmap scan report for 10.73.73.196
Host is up (0.0025s latency).
Nmap scan report for 10.73.73.197
Host is up (0.00063s latency).
Nmap scan report for 10.73.73.198
Host is up (0.00092s latency).
Nmap scan report for 10.73.73.200
Host is up (0.00068s latency).
Host is up (0.00068s latency).
Nmap scan report for 10.73.73.240
Host is up (0.00043s latency).
Nmap scan report for 10.73.73.252
Host is up (0.00032s latency).
Nmap scan report for 10.73.73.253
Host is up (0.0097s latency).

Nmap scan report for 10.73.73.254
Host is up (0.0099s latency).
Nmap done: 256 IP addresses (27 hosts up) scanned in 4.38 seconds

I then connected my Pi and then ran the command again.
nmap -sP 10.73.73.* | tee allIPswithPi.txt

Following are the contents of allIPswithPi.txt

Starting Nmap 5.21 ( http://nmap.org ) at 2014-10-03 12:17 IST
Nmap scan report for 10.73.73.8
Host is up (0.00050s latency).
Nmap scan report for 10.73.73.9
Host is up (0.00049s latency).
Nmap scan report for 10.73.73.17
Host is up (0.00048s latency).
Nmap scan report for 10.73.73.18
Host is up (0.00045s latency).
Nmap scan report for 10.73.73.20
Host is up (0.00036s latency).
Nmap scan report for 10.73.73.22
Host is up (0.00042s latency).
Nmap scan report for 10.73.73.28
Host is up (0.00058s latency).
Nmap scan report for 10.73.73.50
Host is up (0.0036s latency).
Nmap scan report for 10.73.73.52
Host is up (0.00048s latency).

Nmap scan report for 10.73.73.150
Host is up (0.00042s latency).
Nmap scan report for 10.73.73.155
Host is up (0.00037s latency).
Nmap scan report for 10.73.73.162
Host is up (0.00084s latency).
Nmap scan report for 10.73.73.163
Host is up (0.00031s latency).
Nmap scan report for 10.73.73.164
Host is up (0.00030s latency).
Nmap scan report for 10.73.73.175
Host is up (0.0031s latency).
Nmap scan report for 10.73.73.177
Host is up (0.00048s latency).
Nmap scan report for 10.73.73.180
Host is up (0.00033s latency).
Nmap scan report for 10.73.73.181
Host is up (0.00078s latency).
Nmap scan report for 10.73.73.187
Host is up (0.00028s latency).
Nmap scan report for 10.73.73.193
Host is up (0.0027s latency).
Nmap scan report for 10.73.73.196
Host is up (0.0016s latency).
Nmap scan report for 10.73.73.197
Host is up (0.0027s latency).
Nmap scan report for 10.73.73.198
Host is up (0.0027s latency).
Nmap scan report for 10.73.73.200
Host is up (0.0027s latency).
Nmap scan report for 10.73.73.240
Host is up (0.00059s latency).
Nmap scan report for 10.73.73.252
Host is up (0.00044s latency).
Nmap scan report for 10.73.73.254
Host is up (0.0087s latency).
Nmap done: 256 IP addresses (27 hosts up) scanned in 2.86 seconds


I saved both the outputs in separate files and then did a diff. Apart from latency information, most of the IPs were the same and I could see a new entry in the allIPswithPi.txt (10.73.73.52) and one IP was missing from allIPswithPi.txt (10.73.73.253) as compared to allIPs-Pi.txt which was not of concern for me. I was only interested in the new IP in the allIPswithPi.txt.

difference of allIPswithPi.txt and allIPs-Pi.txt
difference of allIPswithPi.txt and allIPs-Pi.txt


You can see the new entry in allIPswithPi.txt on the left hand side in the above image. I tried to ssh it and it indeed was my Pi's IP. So there you go, if all you need is the IP of the raspberry Pi, you don't need to attach a display or invest in any hardware, just run the nmap command and you're done.