0

I use a raspberry Pi 2. I have already installed raspbian and configured to a network using a usb-wifi a while back. Now I've moved to another place and I don't have an ethernet cable/ hdmi connectivity to a display. How can I connect it to a VNC without knowing its IP and without Pi being connected to any network.

  • without Pi being connected to any network well, you can't ... do you have a (wifi) network to connect to? – Jaromanda X Apr 20 '18 at 1:00
  • @JaromandaX Yes I have a network to connect to – Alan JÖzf Pallath Apr 20 '18 at 5:53
1

My hacking instincts tell me it might be possible to connect to the PI without taking out the SD card. If you know the network name and password that the PI usually connects to then you can setup a WiFi hotspot on your smartphone (or another PC if you have access to one) with these credentials to fool the PI to connect to your phone.

3

Your Raspberry Pi must at least associated to a wifi network. Otherwise it is not possible to connect to it. It is the same as if you haven't plugged in an ethernet cable. You can the SD Card put into to a card reader on a pc, mount its fat boot partition (the first partition) and create a file called wpa_supplicant.conf with necessary information for the new network in it. On first boot, this file is copied to /etc/wpa_supplicant/wpa_supplicant.conf, overwriting any existing file with the same name. When the raspi is associated to the network, then you can scan for its ip address (given that there is a dhcp server) with a network scanner from your pc also connected to the wifi. For example with linux you can use nmap (don't know what scanners are available on other operating systems):

pc ~$ sudo nmap -sn 192.168.1.0/24

Of course you have to know the ip address range of your network and use that. With the ip address of the raspi you can connect with VNC.

If you have access to the dhcp server you can look there, what ip address it has given to the raspi.


I have updated the answer with suggestion from the comment by @Jaromanda X.

  • 2
    My hacking instincts tell me it might be possible to connect to the PI without taking out the SD card. If you know the network name and password that the PI usually connects to then you can setup a WiFi hotspot on your smartphone (or another PC if you have access to one) with these credentials to fool the PI to connect to your phone. – John Hawthorne Apr 19 '18 at 14:36
  • @JohnHawthorne cool idea (^.^)d – Ingo Apr 19 '18 at 19:29
  • 1
    might be good to know that you can update a headless pi's wpa_supplicant.conf by creating a file in the "boot" partition called wpa_supplicant.conf with necessary information in it. On first boot, this file is copied to /etc/wpa_supplicant/wpa_supplicant.conf, overwriting any existing file with the same name – Jaromanda X Apr 20 '18 at 1:04
  • @JohnHawthorne that's one cool idea. I'm gonna try that. Will update soon! – Alan JÖzf Pallath Apr 20 '18 at 5:53
  • @JohnHawthorne it actually worked! Can you put it as an answer? I'll mark it as the answer. It's by far the most simplest solution I've seen in this thread and it worked. – Alan JÖzf Pallath Apr 24 '18 at 6:27
1

If you have it actually connecting to wifi, and it is a local wifi network (not a large corporate one), Raspberry Pi's actually advertise via bonjero/zeroconf network as raspberrypi.local (or hostname.local if you've changed it).

This means that if you install a client for bonjour on your computer, you should be able to attempt (ssh, ping, network services) at raspberrypi.local without needing to know the IP address that this Pi has taken.

0

It sounds like you're on your way to solving part of your problem by making the appropriate changes to /etc/wpa_supplicant/wpa_supplicant.conf. If you still need to know the IP address, you really don't need nmap at all. You can take advantage of the fact that all RPis have the same first three octets of their MAC address (the first 3 octets are known as the organizationally unique identifier (OUI), in this case the Raspberry Pi "organization"). Anyway... the value of these octets are: b8:27:eb. A compact shell script can ferret out the IP addresses you need:

#!/bin/sh

: ${1?"Usage: $0 ip subnet to scan. eg '192.168.1.'"}

subnet=$1

for addr in seq 0 1 255; do ( ping -c 3 -t 5 $subnet$addr > /dev/null ) &

done

arp -a | grep b8:27:eb

Copy this to a file (e.g. findpi.sh), make it executable (chmod 744 findpi.sh), and run it (./findpi.sh 192.168.1. - or whatever your network addr is)

  • You have max. 255 pings working in the background that may not have finished when you ask the arp cache. It is possible the searched ip address isn't pinged at that time and not in the arp cache. – Ingo Apr 28 '18 at 15:50
  • You're correct of course, but as a practical matter, and in most LAN configurations, do you believe that is that going to be an issue? And I suppose if you were concerned about it, don't run it in the background. I'm just trying to help with a very common problem in a 'quick and dirty' way, but new ideas to improve are more than welcome :) – Seamus Apr 29 '18 at 21:44
  • You have made an answer. There is no criticism you have made it ;-). At least a second try with your script will find the ip address. Comments are mainly meant to improve and optimize answers, e.g. you could use GNU parallel for pinging. This will improve execution time significantly but terminates only when all pings are done, means no problem with not pinged arp cache. You can also optimize ping with -c 1 and/or -i 0.2. -t 1 is better than -t 5 because you only see neighbors anyway in the arp cache. (Haven't tested this suggestions). – Ingo Apr 30 '18 at 9:15
  • Thank you; these are good and reasonable suggestions, and I will try them at my next opportunity. – Seamus May 14 '18 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.