mirror of
https://github.com/m8tin/cis.git
synced 2025-12-06 07:48:26 +01:00
added net scripts
This commit is contained in:
19
script/host/net/printAllShortManagedHostnamesFromHostsFile.sh
Executable file
19
script/host/net/printAllShortManagedHostnamesFromHostsFile.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Select just lines containing 'managedHost'.
|
||||
# 1.) Remove everything after a '#' (including the #).
|
||||
# 2.) Remove every indenting.
|
||||
# 3.) Remove blanks (spaces or tabs) at the end of lines.
|
||||
# 4.) Replace blanks (spaces or tabs) with one ';' between the values.
|
||||
# 5.) Delete empty lines.
|
||||
# Then cut the second field
|
||||
# Then cut the first field to get the short hostname
|
||||
grep 'managedHost' /etc/hosts \
|
||||
| sed -e 's/#.*//' \
|
||||
-e 's/^[[:blank:]]*//' \
|
||||
-e 's/[[:blank:]]*$//' \
|
||||
-e 's/\s\+/;/g' \
|
||||
-e '/^$/d' \
|
||||
| cut -d';' -f2 \
|
||||
| cut -d'.' -f1
|
||||
|
||||
4
script/host/net/printOwnDefaultMACAdress.sh
Executable file
4
script/host/net/printOwnDefaultMACAdress.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
cat /sys/class/net/e*/address \
|
||||
| head -n 1
|
||||
108
script/host/net/printOwnIPv4Adress.sh
Executable file
108
script/host/net/printOwnIPv4Adress.sh
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/bin/bash
|
||||
|
||||
#grep -E '(:|^(127|169\.254|10|172\.(1(6|7|8|9)|2[0-9]|30|31)|192\.168|(22(4|5|6|7|8|9)|23(0|1|2|3|4|5|6|7|8|9))).*)' findet:
|
||||
# loopback: 127.0.0.0/8
|
||||
# linklocal: 169.254.0.0/16
|
||||
# private: 10.0.0.0/8,
|
||||
# 172.16.0.0/12, (172.16… bis 172.31…)
|
||||
# 192.168.0.0/16
|
||||
# multicast: 224.0.0.0/4 (224… bis 239…)
|
||||
|
||||
|
||||
function all() {
|
||||
# Select just lines containing 'inet'.
|
||||
# 1.) Remove every indenting.
|
||||
# 2.) Remove 'inet '.
|
||||
# 3.) Remove everything after a '/' (including the /).
|
||||
ip -4 addr \
|
||||
| grep 'inet' \
|
||||
| sed -e 's/^[[:blank:]]*//' \
|
||||
-e 's/inet //' \
|
||||
-e 's/\/.*//'
|
||||
}
|
||||
|
||||
function routed() {
|
||||
local _DEVICE
|
||||
_DEVICE="$(ip -4 route show default | xargs -n 1 | grep -A1 -i dev | tail -n 1)"
|
||||
readonly _DEVICE
|
||||
|
||||
ip -4 addr show dev "${_DEVICE:?"Missing DEVICE"}" scope global \
|
||||
| grep 'inet' | xargs -n 1 \
|
||||
| grep -A1 'inet' \
|
||||
| tail -n 1 \
|
||||
| cut -d/ -f1
|
||||
}
|
||||
|
||||
function public() {
|
||||
hostname -I | xargs -n 1 \
|
||||
| grep -vE '(:|^(127|169\.254|10|172\.(1(6|7|8|9)|2[0-9]|30|31)|192\.168|(22(4|5|6|7|8|9)|23(0|1|2|3|4|5|6|7|8|9))).*)'
|
||||
}
|
||||
|
||||
# Maybe use "resolvectl status" to get DNS Server and specify 'nslookup'
|
||||
function published() {
|
||||
local _BOOT_HOSTNAME
|
||||
_BOOT_HOSTNAME="$(hostname -b)"
|
||||
readonly _BOOT_HOSTNAME
|
||||
|
||||
nslookup -type=A "${_BOOT_HOSTNAME:?"Missing BOOT_HOSTNAME"}" | xargs -n 1 \
|
||||
| grep -A2 -i "${_BOOT_HOSTNAME}" \
|
||||
| grep -A1 -i 'address' \
|
||||
| tail -n1
|
||||
}
|
||||
|
||||
function verified() {
|
||||
local _PUBLISHED_IP
|
||||
_PUBLISHED_IP="$(published)"
|
||||
readonly _PUBLISHED_IP
|
||||
|
||||
[ -z "${_PUBLISHED_IP}" ] \
|
||||
&& return 0
|
||||
|
||||
all | grep "${_PUBLISHED_IP}"
|
||||
}
|
||||
|
||||
function usage() {
|
||||
echo "Use one of the following options:"
|
||||
echo " --all : prints all IPv4 addresses"
|
||||
echo " --routed : prints the IPv4 address used to send traffic to the default gateway"
|
||||
echo " --public : prints all IPv4 addresses direct accessable from the internet"
|
||||
echo " --published : prints the IPv4 address provided by DNS using this host's name"
|
||||
echo " --verified : prints the IPv4 included in 'all' und respended by 'published'"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function main(){
|
||||
|
||||
case "${1}" in
|
||||
--all)
|
||||
all
|
||||
return 0
|
||||
;;
|
||||
--routed)
|
||||
routed
|
||||
return 0
|
||||
;;
|
||||
--public)
|
||||
public
|
||||
return 0
|
||||
;;
|
||||
--published)
|
||||
published
|
||||
return 0
|
||||
;;
|
||||
--verified)
|
||||
verified
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
main "$@" && exit 0 || exit 1
|
||||
109
script/host/net/printOwnIPv6Adress.sh
Executable file
109
script/host/net/printOwnIPv6Adress.sh
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
|
||||
#grep -E '(^::1|(^fc.*|^fd.*)|^fe80::.*|^ff.*)' findet:
|
||||
# loopback: ::1/128
|
||||
# uniquelocal: fc00::/7 (fc00… bis fdff…)
|
||||
# linklocal: fe80::/64
|
||||
# multicast: ff00::/8 (ff…)
|
||||
|
||||
|
||||
|
||||
function all() {
|
||||
# Select just lines containing 'inet6'.
|
||||
# 1.) Remove every indenting.
|
||||
# 2.) Remove 'inet6 '.
|
||||
# 3.) Remove everything after a '/' (including the /).
|
||||
ip -6 addr \
|
||||
| grep 'inet6' \
|
||||
| sed -e 's/^[[:blank:]]*//' \
|
||||
-e 's/inet6 //' \
|
||||
-e 's/\/.*//'
|
||||
}
|
||||
|
||||
function routed() {
|
||||
local _DEVICE
|
||||
_DEVICE="$(ip -6 route show default | xargs -n 1 | grep -A1 -i dev | tail -n 1)"
|
||||
readonly _DEVICE
|
||||
|
||||
ip -6 addr show dev "${_DEVICE:?"Missing DEVICE"}" scope global \
|
||||
| grep 'inet6' \
|
||||
| xargs -n 1 \
|
||||
| grep -A1 'inet6' \
|
||||
| grep ':' \
|
||||
| cut -d/ -f1
|
||||
}
|
||||
|
||||
function public() {
|
||||
hostname -I | xargs -n 1 \
|
||||
| grep ':' \
|
||||
| grep -vE '(^::1|(^fc.*|^fd.*)|^fe80::.*|^ff.*)'
|
||||
}
|
||||
|
||||
# Maybe use "resolvectl status" to get DNS Server and specify 'nslookup'
|
||||
function published() {
|
||||
local _BOOT_HOSTNAME
|
||||
_BOOT_HOSTNAME="$(hostname -b)"
|
||||
readonly _BOOT_HOSTNAME
|
||||
|
||||
nslookup -type=AAAA "${_BOOT_HOSTNAME:?"Missing BOOT_HOSTNAME"}" | xargs -n 1 \
|
||||
| grep -A2 -i "${_BOOT_HOSTNAME}" \
|
||||
| grep -A1 -i address \
|
||||
| tail -n1
|
||||
}
|
||||
|
||||
function verified() {
|
||||
local _PUBLISHED_IP
|
||||
_PUBLISHED_IP="$(published)"
|
||||
readonly _PUBLISHED_IP
|
||||
|
||||
[ -z "${_PUBLISHED_IP}" ] \
|
||||
&& return 0
|
||||
|
||||
all | grep "${_PUBLISHED_IP}"
|
||||
}
|
||||
|
||||
function usage() {
|
||||
echo "Use one of the following options:"
|
||||
echo " --all : prints all IPv6 addresses"
|
||||
echo " --routed : prints the IPv6 address used to send traffic to the default gateway"
|
||||
echo " --public : prints all IPv6 addresses direct accessable from the internet"
|
||||
echo " --published : prints the IPv6 address provided by DNS using this host's name"
|
||||
echo " --verified : prints the IPv6 included in 'all' und respended by 'published'"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function main(){
|
||||
|
||||
case "${1}" in
|
||||
--all)
|
||||
all
|
||||
return 0
|
||||
;;
|
||||
--routed)
|
||||
routed
|
||||
return 0
|
||||
;;
|
||||
--public)
|
||||
public
|
||||
return 0
|
||||
;;
|
||||
--published)
|
||||
published
|
||||
return 0
|
||||
;;
|
||||
--verified)
|
||||
verified
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
main "$@" && exit 0 || exit 1
|
||||
3
script/host/net/printOwnMACAdresses.sh
Executable file
3
script/host/net/printOwnMACAdresses.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
cat /sys/class/net/e*/address
|
||||
30
script/host/net/printOwnShortHostnameFromHostsFile.sh
Executable file
30
script/host/net/printOwnShortHostnameFromHostsFile.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Select just lines containing 'inet'.
|
||||
# 1.) Remove every indenting.
|
||||
# 2.) Remove 'inet '.
|
||||
# 3.) Remove everything after a '/' (including the /).
|
||||
# Search each IP of the IPv4-list in file '/etc/hosts'
|
||||
# Select just lines containing 'managedHost'.
|
||||
# 1.) Remove everything after a '#' (including the #).
|
||||
# 2.) Remove every indenting.
|
||||
# 3.) Remove blanks (spaces or tabs) at the end of lines.
|
||||
# 4.) Replace blanks (spaces or tabs) with one ';' between the values.
|
||||
# 5.) Delete empty lines.
|
||||
# Then cut the second field
|
||||
# Then cut the first field to get the short hostname
|
||||
ip -4 addr \
|
||||
| grep 'inet' \
|
||||
| sed -e 's/^[[:blank:]]*//' \
|
||||
-e 's/inet //' \
|
||||
-e 's/\/.*//' \
|
||||
| xargs -i grep {} /etc/hosts \
|
||||
| grep 'managedHost' \
|
||||
| sed -e 's/#.*//' \
|
||||
-e 's/^[[:blank:]]*//' \
|
||||
-e 's/[[:blank:]]*$//' \
|
||||
-e 's/\s\+/;/g' \
|
||||
-e '/^$/d' \
|
||||
| cut -d';' -f2 \
|
||||
| cut -d'.' -f1
|
||||
|
||||
Reference in New Issue
Block a user