User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 9:50 pm

And I've also got a bug. I've tried it out on a Mac and after installing a ton of stuff with MacPorts, (and figuring out that you have to run it as root; a check to see if you are root would be nice), the UI doesn't work. This is what I see, with no scroll available anywhere. ImageI've looked through the debug, and this seems to be the only thing relevant.

Code: Select all

2015-06-16 17:45:10.358 Python[79085:3665173] modalSession has been exited prematurely - check for a reentrant call to endModalSession:
There are 10 types of people: those who understand binary and those who don't.

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:28 pm

Ok, I'm giving up for today.
I will debug the mac issue tomorrow, but it looks like version problem (is it qt4 and pyqt4 ...?!)

For the A+ it seems that the problem is nmap version related :
Nmap can only retrieve the MAC address if you are scanning hosts on the local subnet, directly reachable via layer 2 (ethernet or wifi). When you scan hosts across a router (default gateway), your scanning host will talk to the router on layer 2 when sending/receiving layer 3 packets, and thus, Nmap would only be able to see the router's MAC address, but not the destination host MAC address. And don't even bother when to try localhost.
http://www.jetsonblog.com
twitter : @nolaan_boy

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: GUI to find raspberry IP address

Tue Jun 16, 2015 10:32 pm

Ok, I'm giving up for today.
:lol:
I will debug the mac issue tomorrow, but it looks like version problem (is it qt4 and pyqt4 ...?!)
The package I installed with MacPorts was called py27-pyqt4. I opened up a Python shell and imported PyQt4 all right with no errors, so I assume its working fine. I'll keep looking myself as well. Looks nice from the pictures though! :D
There are 10 types of people: those who understand binary and those who don't.

User avatar
DougieLawson
Posts: 35533
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:12 pm

If I run nmap from the command line with nmap -sn -oX stuff.xml 10.1.1.0/24 I get MAC addresses for every device on my network.

This scan works on my A+

Code: Select all

#!/usr/bin/env python
# -*- coding: latin-1 -*-
import sys
import os
import nmap                         # import nmap.py module
try:
    nm = nmap.PortScanner()         # instantiate nmap.PortScanner object
except nmap.PortScannerError:
    print('Nmap not found', sys.exc_info()[0])
    sys.exit(1)
except:
    print("Unexpected error:", sys.exc_info()[0])
    sys.exit(1)
print('----------------------------------------------------')
nm.scan('10.1.1.0/24', arguments='-sn')
print nm.command_line()                   
print('----------------------------------------------------')
for x in nm.all_hosts():
  print x, nm[x].hostname()
  try:
    print nm[x]['addresses']['mac']
  except:
    print "XE:ER:RO:OR:RR:RX"
  print "---"
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil 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

Wed Jun 17, 2015 7:14 am

@DougieLawson :o :o I run the exact same command :oops: :oops:
@kusti8 Thanks, can you try https://github.com/Nolaan/pyqt-tetris this pyqt to see if it works properly?
http://www.jetsonblog.com
twitter : @nolaan_boy

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

Re: GUI to find raspberry IP address

Wed Jun 17, 2015 7:19 am

Nolaan wrote:@DougieLawson :o :o I run the exact same command :oops: :oops:
Then I'm more puzzled than ever. That scan works for me. I've not looked at how you parse the results.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil 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

Wed Jun 17, 2015 7:34 am

Actually maybe not the exactly the same since I'm using the argument 'hosts=...'
This is the output I have from your script :

Code: Select all

[email protected]:~# python test.py 
----------------------------------------------------
nmap -oX - -sn 10.42.0.0/24
----------------------------------------------------
10.42.0.1 
B8:6B:23:AC:FC:13
---
10.42.0.167 raspberrypi
XE:ER:RO:OR:RR:RX
---

http://www.jetsonblog.com
twitter : @nolaan_boy

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

Re: GUI to find raspberry IP address

Wed Jun 17, 2015 8:32 am

I get this

Code: Select all

----------------------------------------------------
nmap -oX - -sn 10.1.1.0/24
10.1.1.101
32:91:8F:11:05:40
---
10.1.1.138
30:91:8F:11:05:40
---
10.1.1.17
XE:ER:RO:OR:RR:RX
---
10.1.1.230 the-vault.example.bogus
40:4A:03:2C:72:9C
---
10.1.1.249 gutenberg.example.bogus
00:0E:7F:CF:18:79
---
10.1.1.251
00:90:4C:91:00:01
---
10.1.1.26
B8:27:EB:14:46:70
---
10.1.1.27 raspberry.example.bogus
80:1F:02:68:C6:AF
---
10.1.1.32 dhcp-10-1-1-32.example.bogus
08:3E:8E:AB:DE:93
---
10.1.1.41
B8:27:EB:5F:FF:ED
---
10.1.1.49 dhcp-10-1-1-49.example.bogus
80:D2:1D:3C:C7:BF
---
10.1.1.7
00:0F:13:40:18:4F
---
10.1.1.9 eagle.example.bogus
00:F1:40:84:15:1A
---
I think the python nmap parser isn't working (or is horribly buggy code). Every machine has a domain name associated with it, but it's not discovering them all.

10.1.1.17 is the A+ machine that it's being run on, that's why it gets the error MAC address.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil 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

Wed Jun 17, 2015 9:55 am

Ok, I guess we'll leave it as is and get back to it when an nmap update will be available ;)
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

Wed Jun 17, 2015 3:35 pm

I wonder if python-libnmap (https://github.com/savon-noir/python-libnmap) works any better?

Just as a quick test: libnmap-test.py:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Requires netifaces, python-libnmap - install them with pip
# Usage: sudo ./libnmap-test.py
import re, netifaces
from libnmap.process import NmapProcess
from libnmap.parser import NmapParser, NmapParserException

def get_networks():
    """ Scan cards and returns the networks reachable by the
    computer """

    iflist = netifaces.interfaces()
    # Remove localhost
    iflist = [ i for i in iflist if not ('lo' in i )]

    addresses_list = []
    for iface in iflist:
        ad = netifaces.ifaddresses(iface)
        if netifaces.AF_INET in ad.keys():
            addresses_list.append(ad[netifaces.AF_INET][0]['addr'])
    network_list = [re.sub(".\d{1,3}$",".0/24",fname) for fname in addresses_list]

    return network_list


def scan_networks(targets, options):
    parsed = None
    nmproc = NmapProcess(targets, options)
    rc = nmproc.run()
    if rc != 0:
        print("nmap scan failed: {0}".format(nmproc.stderr))

    try:
        parsed = NmapParser.parse(nmproc.stdout)
    except NmapParserException as e:
        print("Exception raised while parsing scan: {0}".format(e.msg))

    return parsed


def filter_results(nmap_report):
    host_list = []
    for host in nmap_report.hosts:
        #if host.status == 'up' and re.match('Raspberry Pi', host.vendor):
        if host.status == 'up':
            hostData = []
            hostData.append(host.address)
            hostData.append(host.mac)
            hostData.append(host.vendor)
            host_list.append(hostData)

    return host_list


if __name__ == "__main__":
    networks = get_networks()
    nmap_report = scan_networks(networks, "-sn")
    if nmap_report:
        host_list = filter_results(nmap_report)
        for host in host_list:
            print(host)
            #print(host[0] + ' | ' + host[1] + ' | ' + host[2])
        print(str(len(host_list)) + " hosts")
    else:
        print("No results returned")
Last edited by ktb on Thu Jun 18, 2015 10:09 am, edited 1 time in total.

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

Re: GUI to find raspberry IP address

Wed Jun 17, 2015 7:54 pm

That got a valid MAC for every machine except the one I ran it on. It correctly identified the four wired Raspberry Pis. But it only found 15 out of the 20 active stations on my network.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

blavery
Posts: 95
Joined: Sun Jul 01, 2012 2:57 am
Location: QLD. Australia

Re: GUI to find raspberry IP address

Wed Jun 17, 2015 11:41 pm

Hmmm,
... all of which seems like a lot of fuss just to read what RPIs exist on the local network.
There are fine GUI net scanners already out there. On this page
http://brian2012class.nfshost.com/headless/
are mentioned several different versions of IP scanner that I use with a RPI/robotics class here on Queensland's Sunshine Coast.

(I use a customised Raspbian for class, and it includes x11vnc server preinstalled on display:0. Many bring a laptop to class in lieu of kbd, mouse & HDMI screen. But of course they all need an easy way to see from the PC what IP the network assigned to their RPi that week - provided they gave their own RPi a unique hostname!)

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

Re: GUI to find raspberry IP address

Thu Jun 18, 2015 7:14 am

... all of which seems like a lot of fuss just to display a desktop environment when you can just xinit --vt2 ; ssh -X [email protected] lxsession :D :D :D :D
As you can see all depends on who you are, I guess people who find it usefull will use it others won't. ;)
http://www.jetsonblog.com
twitter : @nolaan_boy

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

Re: GUI to find raspberry IP address

Thu Jun 18, 2015 7:27 am

I'm unlikely to use this in anger, but it's an interesting programming project and we can all learn something from playing with nmap and the python libraries that are out there to parse the output from nmap.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil 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

Fri Jun 26, 2015 3:26 pm

Goodies time :D ! ==> https://github.com/Nolaan/pyIpFinder

Image

Especially for all the KDE users out there, I added a status led showing on/offline device status, and made the ip/mac text field selectable.
Packages are coming soon for Linux, Mac and Windows
Stay tuned ;)
http://www.jetsonblog.com
twitter : @nolaan_boy

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

Re: GUI to find raspberry IP address

Sat Jun 27, 2015 10:03 pm

Porting the led ui is done ! The script should also be MAC OS friendly .
http://www.jetsonblog.com
twitter : @nolaan_boy

Return to “Python”