Source: https://dzone.com/articles/pi-oi-a-tool-for-finding-local-ip-address-of-your
Download latest version at: https://raw.githubusercontent.com/thoqbk/pi-oi/master/pi-oi.jar
Run pi-oi using command: java -jar pi-oi.jar
Raspberry Pi machine is the most interesting thing I have this year. Why is it interesting? I think because it’s small and very powerful, it can run any program written in my favourite languages like Java, Javascript (Nodejs), PHP. It’s awesome machine which I can’t imagine when I was a student.
I like to write some small applications in Raspberry Pi to control my home appliances remotely. And the first thing I must do before working with Raspberry Pi is open a SSH connection to it. It means that I must know the local IP address of it. I have tried using some tools to scan all devices in my local network to find the dynamic IP that the router set for my Raspberry Pi including arp, ping, nmap, Angry IP scanner (on Windows), Smart IP scanner (on Windows) but all of them did not satisfy me because:
So I decided to develop my own algorithm to resolve all these stuffs. The algorithm uses two following knowledge:
Following is the pseudo code of the algorithm for single thread scanning:
myLocalAddresses <— get local IP addresses //example: 192.168.1.23
for each myLocalAddress in myLocalAddresses do
networkPrefix <— get network prefix of myLocalAddress // example: 192.168.1
initPivot <— get host number of myLocalAddress // example: 23
pendingHostNumbers <— [1,255] - {initPivot} // pending for scanning
pivot, scanningRange <— null
while (pendingHostNumbers is not empty) OR (scanningRange is not null) OR (pivot is not null) do
if scanningRange is null and pivot is null then
scanningRange <— pick range from pendingHostNumbers around initPivot
else if scanningRange is not empty then
scan all ip addresses in scanningRange and print out result if found a machine open SSH port
if last ip address in scanningRange is active
scanningRange <— pick a range from pendingHostNumbers around scanningRange.last
else if first ip address in scanningRange is active
scanningRange <— pick a range in pendingHostNumbers around scanningRange.first
else
scanningRange <— null
pivot <— pick a new pivot from pendingHostNumbers
end if
else if pivot is not null then
scan pivot
if pivot is active then
scanningRange <— pick a range from pendingHostNumbers around pivot
else
pivot <— pick a new pivot from pendingHostNumbers
end if
else
pivot <— pick a new pivot from pendingHostNumbers
scanningRange <— null
end if
end of while
end of for
In the implementation I split the range [1,255] in 5 continuous parts and start a 5-threads executor-service for scanning faster.
I used Java to implement this algorithm and tested in some local networks. Result is Pi-oi usually found my Raspberry Pi in less than 30 seconds. Following are shot screens of my tests:
Test in my home:
Test at my company:
Email: thoqbk@gmail.com
The MIT License (MIT)