Categories
Linux Network Server Shell

Get WAN IP address via shell

Sometimes one needs to get the WAN IP address via shell.

#!/bin/sh

set -e
set -u

C_DIG="$(which dig)"

DEBUG=0

while [[ ${#} -gt 0 ]]; do
    KEY="${1}"

    case "${KEY}" in
        -d|--debug)
            DEBUG=1
            shift
        ;;
    esac
done

QUERY_TYPE="A"
DIG_OPTIONS="+short"

DNS_SERVER="resolver1.opendns.com"
QUERY_VALUE="myip.opendns.com"

# short version: dig @resolver1.opendns.com A myip.opendns.com +short
IP_ADDRESS="$(${C_DIG} @${DNS_SERVER} ${QUERY_TYPE} ${QUERY_VALUE} ${DIG_OPTIONS})"
RC=${?}

# if the IP address could be successfully retrieved by querying OpenDNS echo it and exit
if [ ${RC} -eq 0 ]; then
    if [ ${DEBUG} -eq 1 ]; then
        echo "Server queried: OpenDNS"
    fi

    echo "${IP_ADDRESS}"

    exit 0
fi

DNS_SERVER="ns1-1.akamaitech.net"
QUERY_VALUE="whoami.akamai.net"

# short version: dig @ns1-1.akamaitech.net A whoami.akamai.net +short
IP_ADDRESS="$(${C_DIG} @${DNS_SERVER} ${QUERY_TYPE} ${QUERY_VALUE} ${DIG_OPTIONS})"
RC=${?}

# if the IP address could be successfully retrieved by querying Akamai echo it and exit
if [ ${RC} -eq 0 ]; then
    if [[ "${DEBUG}" == "-d" ]]; then
        echo "Server queried: Akamai"
    fi

    echo "${IP_ADDRESS}"

    exit 0
fi

DNS_SERVER="ns1.google.com"
QUERY_VALUE="o-o.myaddr.l.google.com"
QUERY_TYPE="TXT"

# short version: dig @ns1.google.com TXT o-o.myaddr.l.google.com +short
IP_ADDRESS="$(${C_DIG} @${DNS_SERVER} ${QUERY_TYPE} ${QUERY_VALUE} ${DIG_OPTIONS})"
RC=${?}

# if the IP address could be successfully retrieved by querying Google echo it and exit
if [ ${RC} -eq 0 ]; then
    if [[ "${DEBUG}" == "-d" ]]; then
        echo "Server queried: Google"
    fi

    echo "${IP_ADDRESS}"

    exit 0
fi

exit 1

Source

This has been taken from https://unix.stackexchange.com/a/81699 and put into a small script to provide some kind of failover if one service might not be available.

Categories
Linux Network Netzwerk

SNMP tools

SNMP-Walk with translated OIDs

to prevent translation of OIDs: -On

 

Categories
Linux Network Netzwerk

Connecting to UDP socket

 

Categories
fail2ban Linux Security Server

fail2ban show bans and unban

List jails

List bans of jail

Unban IP in jail

Categories
Linux SSH

SSH tunnel

Tunnel

Port forward

 

Categories
Java Linux Windows

Java debugging

Start the Java application like this

This will start the JVM suspended which means it will only start after connecting. If this is not wanted change

suspended=y

to

suspended=n

Categories
Linux

Check file consistency after copying

Same also works for md5sum etc …

Categories
CUPS Linux Printer

Print from command line

List all printers

Change into directories and print the files

 

If the document type/mime type is not supported check /etc/mailcap.

Necessary package for Fedora is cups-client.

Categories
Linux

SELinux: convert denial to policy

Create a policy .te file by using the following command as an example.

Now follow HOWTO: Build a SELinux Policy and activate it

Categories
CentOS Linux

HOWTO: Build a SELinux Policy and activate it

Build the policy according to

  1. https://www.centos.org/docs/5/html/Deployment_Guide-en-US/sec-sel-building-policy-module.html
  2. https://wiki.gentoo.org/wiki/SELinux/Tutorials/Creating_your_own_policy_module_file
  3. https://wiki.centos.org/HowTos/SELinux

The package selinux-policy-devel is required.