Tag Archive for: Bash

Find Out Who’s on Your Network with One Simple Command

Want to see all devices connected to your local network? Try this quick Linux command:

sudo arp-scan --interface=eno2 -l

What does it do?

  • sudo: Runs with superuser privileges (required for network access).
  • arp-scan: Scans for devices using the ARP protocol.
  • --interface=eno2: Specifies the network interface (like your Ethernet or Wi-Fi).
  • -l: Scans the entire local network (same as --localnet).

What will you see?

  • Each device’s IP address
  • MAC address
  • Device vendor (if recognized)

Great for:

  • Checking who’s connected to your Wi-Fi
  • Spotting unknown or suspicious devices
  • Managing your local network

Connecting to a ModBerry 500 via SSH with Dual Ethernet outside the local network

Context

Industrial devices like the ModBerry 500 often come with multiple Ethernet interfaces — typically with eth0 set to a static IP (e.g., 192.168.0.101) and eth1 (e.g., 192.168.20.118) configured via DHCP on your local network.


In some cases, you’ll want to ensure that a specific interface — for example, eth1 — is used as the primary route for Internet access. This is especially important if you plan to remotely connect to the device via SSH, using a custom external port (like 2223) forwarded through your router.

The Problem

Even if you configure the IP and gateway on eth1, Linux may still use eth0 as the default route, because it automatically assigns routing priorities (metrics). In our case, eth1 ended up with metric 203 and eth0 with 202 — making eth0 the preferred route. That’s the opposite of what we wanted.

The Solution: Prioritize eth1 via /etc/dhcpcd.conf

If your system is using dhcpcd as its network manager (which is common on ModBerry), you can set the interface priority easily.

1. Open the config file:

sudo nano /etc/dhcpcd.conf

2. Add this at the end:

interface eth1
  metric 100

interface eth0
  metric 200

This tells the system: “Use eth1 first, because it has a lower metric.”

3. Restart the service:

sudo systemctl restart dhcpcd

4. Check the active routes:

ip route show

You should see something like:

default via 192.168.120.1 dev eth1 metric 100
default via 192.168.0.99 dev eth0 metric 200

Open SSH Access on Port 2223 via Router NAT (e.g., pfSense)

In this setup, we’re accessing the ModBerry remotely by forwarding a custom external port (like 2223) on the router’s public IP to port 22 on the ModBerry’s eth1 IP address.

1. Set up a NAT Port Forwarding rule on your router (e.g., pfSense)

  • External port: 2223
  • Internal IP: your ModBerry’s eth1 IP (e.g., 192.168.120.118)
  • Internal port: 22 (default SSH port)
  • Protocol: TCP

This tells your router: “When someone connects to port 2223 on the public IP, forward that to port 22 on the ModBerry’s eth1 interface.”

2. From outside your network, connect using:

ssh -p 2223 user@YOUR_PUBLIC_ROUTER_IP

Replace user with your actual ModBerry username (e.g., root or pi), and YOUR_PUBLIC_ROUTER_IP with the WAN IP of your pfSense router.

Convert JPG Images to Optimized WebP

mogrify -format webp -quality 80 -strip -resize "1024x>" *.jpg

This command creates optimized WebP versions of your JPG images while intelligently handling image sizes, only larger images are resized, and smaller ones are left unchanged. The original JPG files remain untouched, with new WebP versions created alongside them.

Use oathtool command line for 2 step verification (2FA)

You don’t need to use GAMMA Authenticators or closed private apps that generates 2 step verification (2FA) codes on your phone. Keep it simple and under your control, use oathtool command:

oathtool -b --totp 'private_key'

This will give you an output with the code you need whenever you want, ex:

521319

Read IO-Link sensor info

First of all, you need to check your IO-Link master and sensor to know how to proceed, but in most cases between different manufacturers is quite similar thanks to IO-Link standard.

Let’s check an IM5184 sensor connected to port 2 in a AL1350 master at 192.168.0.20

curl

curl -d '{"code":"request","cid":1,"adr":"/iolinkmaster/port[2]/iolinkdevice/iolreadacyclic","data":{"index":1002,"subindex":1}}' http://192.168.0.20

httpie

http POST 192.168.0.20 code=request cid:=1 adr=iolinkmaster/port[2]/iolinkdevice/iolreadacyclic data:='{"index":1002, "subindex":1}'

This would give us an hexadecimal value ready to use.

HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json
Transfer-Encoding: chunked

{
    "cid": 1,
    "code": 200,
    "data": {
        "value": "00022FE5"
    }
}