I have two linux devices:
- A: One has static IP (eg. 10.255.253.5 and mask 255.255.255.0). I cannot know or change this IP.
- B: The second has a direct access (Screen and keyboard)
I'd like to connect the two devices directly using an Ethernet cable. For what I understand, the two devices must be on the same subnet to connect to each other. The issue is I don't know which subnet it is.
I've tried to use arp -a
but it only returns IPs on the same subnet (which means none with a direct connection).
How could I scan the whole network (devices are not connected to the Internet nor any other network) to find out the IP and the subnet to connect to ?
Basically, I imagine something like that:
- Scan all possible subnets to list active IPs
- Switch the IP of the B device to match the found subnet
- Connect to the found IP
How would this be possible to achieve ?
EDIT: Following comments, here is what I've made. It works for some devices but not for others...
Grab remote device IP:
tcpdump -i eth0 -s 1500 '(ether[12:2]=0x88cc) -v -c 1 | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' -o
I got IP
10.255.253.5
which is correct.Change local IP to be in the same subnet (remote +1):
ifconfig eth0 10.255.253.6 netmask 255.255.255.0
Ping remote device to check it can be reached:
ping 10.255.253.5
Success !
arp
supports specifying the netmask, you can perhaps specify0.0.0.0
while leaving the device connected to the router.