XionTech
Posts: 8
Joined: Mon Oct 12, 2015 9:48 pm

Network Port Scan

Fri Jul 08, 2016 2:49 am

I'm using my Pi as a simple video stream viewer with omxplayer loading the static IP of my rtsp stream. However, I use this on different networks (including the stream server) so the server and my Pi change IPs. I can't have static since the IP pool is sometimes 10.xxx.xxx.xxx or sometimes 192.xxx.xxx.xxx etc. And I don't always have access to the router. (it's a video relay used in public venues).

Is there a brilliant script that can scan the currently connected network (looking for an rtsp port or a particular file that would be hosted on my server) and return the IP of the server?

User avatar
AikonCWD
Posts: 180
Joined: Mon Jun 09, 2014 3:50 pm
Location: Barcelona

Re: Network Port Scan

Fri Jul 08, 2016 7:39 am

Yes, I recommend you to use nmap. You can scan the entire network in seconds, return the MAC address of each device and get the associated IP. If you provide more information, I can try to code a working script for you.
My e-mail = aikon.bcn@gmail.com

XionTech
Posts: 8
Joined: Mon Oct 12, 2015 9:48 pm

Re: Network Port Scan

Fri Jul 08, 2016 7:53 am

The server is an axis q7401. So I pretty much run a quiet boot on my pi to a bash script which executes omxplayer -*myparams rtsp://ipaddress/axis-media/media.amp

Thank you so much for the assist...

User avatar
DougieLawson
Posts: 38882
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Network Port Scan

Fri Jul 08, 2016 8:16 am

Code: Select all

#!/usr/bin/python
from pyroute2 import IPRoute
import socket
ip = IPRoute()
for x in ip.get_addr(label='eth0',family=socket.AF_INET):
  ipa =x.get_attr('IFA_ADDRESS')+"/"+str(x['prefixlen'])

print "My IP:", ipa
import subprocess
process = subprocess.Popen(['sudo','nmap','-oX', '/tmp/nmap.xml','-sn',ipa],
stdout=subprocess.PIPE)
process.wait()

import xml.etree.ElementTree as ET
tree = ET.parse('/tmp/nmap.xml')
for node in tree.iter('address'):
  try:
    if node.attrib['addrtype'] == "ipv4":
      ip = node.attrib['addr']
  except:
    pass
  try:
    if node.attrib['vendor'] == "Raspberry Pi Foundation":
      print "Other Raspberry IP:", ip
  except:
    pass
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

XionTech
Posts: 8
Joined: Mon Oct 12, 2015 9:48 pm

Re: Network Port Scan

Fri Jul 08, 2016 8:50 am

Can I call a python script from a bash and return an argument (ip) or should I switch to using a python script to retrieve and call the omxplayer from that?

User avatar
AikonCWD
Posts: 180
Joined: Mon Jun 09, 2014 3:50 pm
Location: Barcelona

Re: Network Port Scan

Fri Jul 08, 2016 8:51 am

First install nmap on your Pi

Code: Select all

sudo apt-get install nmap
Than run this command:

Code: Select all

sudo nmap -sP 192.168.0.0/24 | awk '/Nmap scan report for/{printf $5;}/MAC Address:/{print " "$3;}' | grep 7C:05:07:21:35:44 | awk '{print $1}'
Where 192.168.0.0/24 is your network and 7C:05:07:21:35:44 is the MAC address of the device you want to know the IP.
My e-mail = aikon.bcn@gmail.com

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Network Port Scan

Sun Jul 10, 2016 8:58 am

XionTech wrote:... And I don't always have access to the router. (it's a video relay used in public venues).

Is there a brilliant script that can scan the currently connected network (looking for an rtsp port or a particular file that would be hosted on my server) and return the IP of the server?
Note that scanning the network like that might be seen as a breach of the TOS for connecting to the network. Whist many places may not care its possible some venues could have something in place that detects such network scans. </pedantMode>

The obvious alternatives I can think of would be to have the devices send an email with it's internal (and external IP). Or have a small screen that could provide diagnostic information (IP address, streaming state etc).

Return to “Advanced users”