Category Archives: Howto Tutorials (EN)

Howto Tutorials English Contribution Howto’s and Tutorials technical contribution for Professionals

Show my IP address on the Internet

Output the global Internet address in the shell, query local IPv4 and IPv6 addresses in the terminal

Determining the global IP with this one is surfing the Internet, this is also possible in the command line, for Windows, Linux and macOS.

Run the following command in the Linux terminal to query the public global IP address:

curl ipline.ch

Determine the local private IP address with the following command:

$ /sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'

For Linux operating systems installed in German:

$ /sbin/ifconfig eth0 | grep 'inet Adresse' | cut -d: -f2 | awk '{print $1}'

Note: ipconfig is deprecated, for current distributions, such as Ubuntu 18.04 or CentOS 7 and Fedora, the ip command is applied, this command returns IPv4 addresses:

$ ip -4 addr

The slightly clearer and also more colorful version as follows:

$ ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

Only IPv6 addresses should be output:

$ ip -6 addr | grep -oP '(?<=inet6\s)[\da-f:]+'

Also, the hostname command can provide useful values:

$ hostname -i | awk '{print $3}'

Show IP address on macOS


macOS returns the IP address from the terminal with the following command.

$ /sbin/ifconfig en0 | awk '/inet /{print $2}'

And the hostname command is also available on macOS:

$ hostname -I

Find Windows IP address

Windows uses ipconfig to output the IP addresses.

C:\> ipconfig /all

Also only IPv4 addresses can be queried:

C:\> ipconfig | findstr /i "ipv4"

To reduce the amount of information that ipconfig generates, command wmic can help.

C:\> wmic NICCONFIG GET IPAddress

This query e.g. outputs the IP address of each interface.

C:\> netsh interface ipv4 show address

View IP addresses in the PowerShell with Get-NetIPAddress, useful also in scripts

PS C:\> Get-NetIPAddress | Format Table

Again, only IPv4 addresses can be queried:

PS C:\> Get-NetIPAddress -AddressFamily IPv4 | Format Table

By typing Get-NetIPAddress -? all parameters to the cmdlet are output.

View public IP address and local private IP address in powershell

$GlobalIP = Invoke-RestMethod -Uri http://ipline.ch/echo
$PrivatIP = $(Get-NetIPAddress -InterfaceIndex 11 -AddressFamily IPv4).IPAddress
Write-Host "Meine öffentliche IPv4 Adresse ist:" $GlobalIP
Write-Host "Meine private IPv4 Adresse ist:" $PrivatIP

How to use Wake On lan

Wake on LAN use on Linux, Windows, and Synology

To start remote devices – Wake on LAN (WOL) is a standard released by AMD in collaboration with HPE in 1995 to boot off computers from the NIC that support these ACPI. A general requirement for WOL is that the network card continues to be powered by the power supply’s standby power, even when the computer is turned off.

The network card is waiting for a magic packet to be received. The data packet is either addressed directly to the network card or is sent as broadcast. It contains the hexadecimal value FF six times in a row; Immediately afterwards, the continuous repetition of the MAC address of the network card of the respective target system appears 16 times.

Wake on LAN on Linux

GNU/Linux offers a CLI Command to start a computer.

/usr/bin/wakeonlan -p 7 -i 10.199.3.19 00:11:22:33:44:55

Ubuntu and Debian awaken computers with wakeonlan.

wakeonlan 00:00:33:44:55:66
Sending magic packet to 255.255.255.255:9 with 00:22:33:44:55:66

Fedora CentOS/RHEL on the other hand awakens with ether-wake.

sudo ether-wake -i eno1 00:11:22:33:44:55

Wake on LAN on Synology DSM

Synology has its own tool with synonet in the Busybox Shell.

synonet --wake xx:xx:xx:xx:xx:xx ethX

where -i eno1 means the Ethernet interface.

Wake on LAN for Windows

Microsoft Windows does not have a WOL onboard, a reliable WOL offers WakeMeOnLan from Nirsoft here.

Wakemeonlan

Wake on LAN on macOS

Since macOS also comes with Python by default, you can get a script, the following lines allow a Wake On LAN on the Mac.

#!/usr/bin/env python

import socket
import sys

if len(sys.argv) < 3:
    print "Usage: wake.py <IP> <MAC>   (example: 192.168.1.255 00:11:22:33:44:55)"
    sys.exit(1)

mac = sys.argv[2]
data = ''.join(['FF' * 6, mac.replace(':', '') * 16])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(data.decode("hex"), (sys.argv[1], 9))

Save the script and run it from the OSX terminal.

python wake.py 192.168.1.255 00:11:22:33:44:55