Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

GUI to find raspberry IP address

Tue Jun 16, 2015 1:09 am

Hello,
I've made a Graphical User Interface here => https://github.com/Nolaan/pyIpFinder in qt4. I couldnt find such a tool for a project I'm currently working on so I decided to write it, and share it with the community.
This tool will help you find ALL Pis on the network of your computer, and display it in a window. You may be root to execute it.
Let me know if you have any question of issue with the program

Thanks ;)
Image
Image
Image
Image

Prerequesite : install pyqt4 and nmap
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 7:57 am

It doesn't work on my network. Doesn't find the four raspberry pis that are wired.

This shell script does a better job

Code: Select all

#!/bin/bash
IP=$(ipcalc `hostname -I` | awk '/Network/{print $2}')
MAC=$(sudo nmap -n -sP $IP | awk '/Nmap/ {if (x) {if (x ~ /B8:27/) {split(x, m); print m[5] " " m[13];} x="";}} {x=(!x)?$0:x" "$0;}')
echo $IP
echo $MAC
needs ipcalc installed to convert a discrete IP address into the CIDR for my network.

It's not difficult to discover the network in python

Code: Select all

#!/usr/bin/python
import socket
import nmap

testIP = "8.8.8.8"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((testIP, 0))
ipaddr = s.getsockname()[0].split('.')
ipaddr[3] = '0'

network =""
for dot in ipaddr:
  network += dot+"."
network=network[:-1] # remove the trailing dot.
print network
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 8:15 am

Slightly off-topic, but you could replace:

Code: Select all

network =""
for dot in ipaddr:
  network += dot+"."
network=network[:-1] # remove the trailing dot.
with just

Code: Select all

network = ".".join(ipaddr)
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 9:22 am

@DougieLawson : Thanks, I've forgot half the files. I've uploaded the nmap library ;)

PS : I'll try to package it this with (deb and rpm)
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 9:42 am

The new version still fails to find any Raspberries on my network.

Code: Select all

[email protected] /tmp/pyIpFinder # DISPLAY=:1 ./pyIpFinder.py
Launching threaded scan
Scan init done
Launched threaded scan
Scan started!
Scan ended!
The scan returned an empty list
Emitted
updating :D
[email protected] /tmp/pyIpFinder #
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 9:49 am

You just have to relaunch the app.
What happened is I'm trying to avoid people exit and relaunching the program, so I'm reloading the library path dynamically which fails since root user doesn't have /home/root directory.
I've corrected it ;)
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 9:55 am

Still doesn't work.

I tried running it as root and as pi.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 10:00 am

Try to pull the latest and provide me with a screenshot please.

PS : Do you have the python-nmap directory in the tree?
http://www.jetsonblog.com
twitter : @nolaan_boy

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 10:42 am

It didn't work for me without modification. I just tried it on Ubuntu 15.04 x86_64.

It seems to work after this change:

Code: Select all

    addresses_list = re.findall("inet addr:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",ifconfig)
    addresses_list = [re.sub("inet addr:","",fname ) for fname in addresses_list]
And sudo/root was required:
sudo ./pyIpFinder.py

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 10:56 am

My bad :(
The assumption was that ifconfig was portable and the output the same with all distros, apparently not. I'll convert this portion in python to make it more portable. Then it might even work on Windows.
Thanks for the testing.
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 10:56 am

ktb wrote:It didn't work for me without modification. I just tried it on Ubuntu 15.04 x86_64.

It seems to work after this change:

Code: Select all

    addresses_list = re.findall("inet addr:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",ifconfig)
    addresses_list = [re.sub("inet addr:","",fname ) for fname in addresses_list]
And sudo/root was required:
sudo ./pyIpFinder.py
Your change still fails for me

Code: Select all

[email protected] /tmp/pyIpFinder # DISPLAY=:1 ./pyIpFinder.py
Traceback (most recent call last):
  File "./pyIpFinder.py", line 55, in run
    rpi_list = filter_results(scan_list(get_networks()))
  File "./pyIpFinder.py", line 170, in filter_results
    if 'mac' in nm[device]['addresses']:
KeyError: 'addresses'
Traceback (most recent call last):
  File "./pyIpFinder.py", line 55, in run
    rpi_list = filter_results(scan_list(get_networks()))
  File "./pyIpFinder.py", line 170, in filter_results
    if 'mac' in nm[device]['addresses']:
KeyError: 'addresses'
[email protected] /tmp/pyIpFinder #
Note: I'm running it on an A+ which does NOT have an eth0 interface.

ifconfig -a gives me
[email protected] /tmp/pyIpFinder # ifconfig -a
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1100 (1.0 KiB) TX bytes:1100 (1.0 KiB)

wlan0 Link encap:Ethernet HWaddr c8:3a:35:xx:xx:xx
inet addr:xxx.xxx.xxx.xxx Bcast:xxx.xxx.xxx.255 Mask:255.255.255.0
[... global IPv6 address redacted ...]
inet6 addr: fe80::ca3a:35ff:fexx:xxxx/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:268579 errors:0 dropped:17 overruns:0 frame:0
TX packets:78903 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:97003416 (92.5 MiB) TX bytes:14973166 (14.2 MiB)

[email protected] /tmp/pyIpFinder #

If you use my python program to determine the network address it's 100% portable.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 11:13 am

Is it Open Source??? :?: :?: :?:
Just kidding ;) I will since it'll save me time.
http://www.jetsonblog.com
twitter : @nolaan_boy

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 11:41 am

Dougie, I wonder which version of nmap you are using.
Mine:

Code: Select all

$ nmap --version

Nmap version 6.47 ( http://nmap.org )
Platform: x86_64-pc-linux-gnu
Compiled with: liblua-5.2.3 openssl-1.0.1f libpcre-8.35 libpcap-1.6.2 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select
What do you get from adding in a print(nm[device]) ?

Code: Select all

        for device in nm.all_hosts():
            print(nm[device])
            if 'mac' in nm[device]['addresses']:

Code: Select all

{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': '', 'vendor': {u'E4:F4:C6:XX:XX:XX': u'Netgear'}, 'addresses': {u'mac': u'E4:F4:C6:XX:XX:XX', u'ipv4': u'192.168.X.X'}}
{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': '', 'vendor': {u'00:D0:2D:XX:XX:XX': u'Ademco'}, 'addresses': {u'mac': u'00:D0:2D:XX:XX:XX', u'ipv4': u'192.168.X.XXX'}}
{'status': {'state': u'up', 'reason': u'localhost-response'}, 'hostname': '', 'vendor': {}, 'addresses': {u'ipv4': u'192.168.X.XXX'}}
{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': '', 'vendor': {u'60:BE:B5:XX:XX:XX': u'Motorola Mobility'}, 'addresses': {u'mac': u'60:BE:B5:XX:XX:XX', u'ipv4': u'192.168.X.XXX'}}
{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': '', 'vendor': {u'B8:27:EB:XX:XX:XX': u'Raspberry Pi Foundation'}, 'addresses': {u'mac': u'B8:27:EB:XX:XX:XX', u'ipv4': u'192.168.X.XXX'}}
{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': '', 'vendor': {}, 'addresses': {u'mac': u'90:68:C3:XX:XX:XX', u'ipv4': u'192.168.X.XXX'}}
{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': '', 'vendor': {u'E0:CB:4E:XX:XX:XX': u'Asustek Computer'}, 'addresses': {u'mac': u'E0:CB:4E:XX:XX:XX', u'ipv4': u'192.168.X.X'}}

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 11:42 am

Code: Select all

[email protected] ~ # nmap -v

Starting Nmap 6.00 ( http://nmap.org ) at 2015-06-16 12:42 BST
Read data files from: /usr/bin/../share/nmap
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.99 seconds
           Raw packets sent: 0 (0B) | Rcvd: 0 (0B)
[email protected] ~ #
that's the stock standard Raspbian Wheezy version.

My Jessie systems have

Code: Select all

[email protected] ~ # nmap -v

Starting Nmap 6.47 ( http://nmap.org ) at 2015-06-16 12:43 BST
Read data files from: /usr/bin/../share/nmap
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.51 seconds
           Raw packets sent: 0 (0B) | Rcvd: 0 (0B)
[email protected] ~ #
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 11:50 am

Adding a print get

[email protected] /tmp/pyIpFinder # DISPLAY=:1 ./pyIpFinder.py
{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': ''}
Traceback (most recent call last):
File "./pyIpFinder.py", line 55, in run
rpi_list = filter_results(scan_list(get_networks()))
File "./pyIpFinder.py", line 171, in filter_results
if 'mac' in nm[device]['addresses']:
KeyError: 'addresses'
{'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': ''}
Traceback (most recent call last):
File "./pyIpFinder.py", line 55, in run
rpi_list = filter_results(scan_list(get_networks()))
File "./pyIpFinder.py", line 171, in filter_results
if 'mac' in nm[device]['addresses']:
KeyError: 'addresses'
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 12:22 pm

Okay guys, just pushed a more portable version using python. Thanks Dougie I also had to use netifaces, another python module, since I need to search all cards addresses.
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 3:04 pm

The new netifaces code works. The problem is with parsing the XML that nmap outputs. I'm still getting

Code: Select all

Traceback (most recent call last):
  File "./pyIpFinder.py", line 75, in run
    rpi_list = filter_results(scan_list(get_networks()))
  File "./pyIpFinder.py", line 177, in scan_list
    nm.scan(hosts=trunk, arguments='-sn')
  File "/usr/lib/python2.7/dist-packages/nmap/nmap.py", line 241, in scan
    raise PortScannerError(nmap_err)
nmap.nmap.PortScannerError: u'RTTVAR has grown to over 2.3 seconds, decreasing to 2.0\n'
Traceback (most recent call last):
  File "./pyIpFinder.py", line 75, in run
    rpi_list = filter_results(scan_list(get_networks()))
  File "./pyIpFinder.py", line 190, in filter_results
    if 'mac' in nm[device]['addresses']:
KeyError: 'addresses'
when I run it on my Aplus.

It worked perfectly OK on my Pi2B running Jessie. So I wonder if it's the missing eth0 that's killing it on the A+ (although I can see it doing the NMAP because it takes a long time to scan my network which has 21 hosts on it).

I learned a new trick today. I didn't know nmap could emit XML as it's output.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 4:08 pm

Could you provide the output of the following code executed on your A+ ?
(directly invoking python from the terminal)

Code: Select all

import netifaces
netifaces.interfaces()
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 4:52 pm

[email protected] /tmp/pyIpFinder $ python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import netifaces
>>> netifaces.interfaces()
['lo', 'wlan0']
>>>
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 5:21 pm

Ok, I will write a version with a debug flag. It's puzzling me since all interfaces are discovered. Maybe your wifi isn't associated :cry:
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 6:13 pm

Nolaan wrote:Ok, I will write a version with a debug flag. It's puzzling me since all interfaces are discovered. Maybe your wifi isn't associated :cry:
My WiFi is associated, because I'm running it with a VNC session from my laptop.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 7:41 pm

You can pull the last code, it's now traceable ! Use ./pyIpFinder -l debug .
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 8:02 pm

Nolaan wrote:You can pull the last code, it's now traceable ! Use ./pyIpFinder -l debug .
I've sent you a private message with a couple of pastebin URLs.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 9:22 pm

Thanks you found a bug in the filter_result function.
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
DougieLawson
Posts: 35811
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 9:36 pm

Still not working here's the console log

Code: Select all

[email protected] /tmp/pyIpFinder # DISPLAY=:1 ./pyIpFinder.py -l debug > /tmp/ipFinder                                       .log
Traceback (most recent call last):
  File "./pyIpFinder.py", line 100, in run
    rpi_list = filter_results(scan_list(get_networks()))
  File "./pyIpFinder.py", line 232, in filter_results
    if 'mac' in nm[ip]['addresses']:
KeyError: 'addresses'
[email protected] /tmp/pyIpFinder # 
and the tail of the log

Code: Select all

2015-06-16 22:33:27,876 - scan_list - DEBUG - Found device with ip addr : 10.1.1.9
2015-06-16 22:33:27,878 - scan_list - DEBUG - We return this device list : ['10.1.1.101', '10.1.1.11', '10.1.1.13', '10.1.1.138', '10.1.1.17', '10.1.1.230', '10.1.1.249', '10.1.1.251', '10.1.1.26', '10.1.1.27', '10.1.1.32', '10.1.1.40', '10.1.1.41', '10.1.1.43', '10.1.1.44', '10.1.1.47', '10.1.1.49', '10.1.1.6', '10.1.1.9']
2015-06-16 22:33:28,423 - filter_results - DEBUG - nm.all_hosts() gives : [u'10.1.1.101']
2015-06-16 22:33:28,425 - filter_results - DEBUG - Inspecting device : 10.1.1.101
2015-06-16 22:33:28,427 - filter_results - DEBUG - nm[10.1.1.101] : {'status': {'state': u'up', 'reason': u'arp-response'}, 'hostname': ''}
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Python”