Network related bash question

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

Koentje wrote: Wed Jan 31, 2024 9:49 pm But you need to edit the /etc/host file for this one. Add all hostnames and ip's.
ok, in my /etc directory I have the following files:

host.conf
hostid
hostname
hosts
hostsallow
hostsdeny

I assume its host.conf but can you please confirm?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
found all this in hosts so it's obviously hosts. Im beginning edits now.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

Im getting told that hosts is a read only file and I dont have permission to change it. what do I do please?

Im assuming re-edit from terminal as sudo?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

Im good, chatgpt3.5 walked me thru using sudo nano hosts and I have confirmed the file saved teh new data, the display on my screen just populated more net devices!

working on positioning it on screen now :D

Thank you Koentje!!
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Network related bash question

Post by Koentje »

You're welcome.
Was indeed hostS.. dumb typo, i need sleep! :oops:

Screenshots or it didn't happen!! :mrgreen:
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

Koentje wrote: Wed Jan 31, 2024 10:50 pm You're welcome.
Was indeed hostS.. dumb typo, i need sleep! :oops:

Screenshots or it didn't happen!! :mrgreen:
Oh it happened :D

Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

My bottom left widget doesnt look anything like your screenshot.

I don't seem to be getting the colors based on signal strength you mentioned
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

I have a request for after you've gotten some sleep!

on the networkpc2 conky, can the respective IP numbers be displayed under the device names and to the right of the ONLINE/OFFLINE status display?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Network related bash question

Post by Koentje »

That screenshot is sooo small i can't see what is going on..
Image
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Network related bash question

Post by Koentje »

Logansfury wrote: Wed Jan 31, 2024 11:02 pm I have a request for after you've gotten some sleep!

on the networkpc2 conky, can the respective IP numbers be displayed under the device names and to the right of the ONLINE/OFFLINE status display?
Yes i think that can be done... in fact you can leave online/offline out because the icons tell you that. And instead put the ip's there..
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

Koentje wrote: Wed Jan 31, 2024 11:05 pm
Logansfury wrote: Wed Jan 31, 2024 11:02 pm I have a request for after you've gotten some sleep!

on the networkpc2 conky, can the respective IP numbers be displayed under the device names and to the right of the ONLINE/OFFLINE status display?
Yes i think that can be done... in fact you can leave online/offline out because the icons tell you that. And instead put the ip's there..
I would prefer both! I took down the font size a bit to better match my GUI, and 3 more devices turned up partially visible. I had to expand the min vert figure. I have a ghost device! At the bottom of my list is an online device icon with no IP or online status:

Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Network related bash question

Post by Koentje »

Count icons and textlines... both the same. Problem is, you resized the fontsize and now you have to align the offsets in both online and offline lines in the script
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

Koentje wrote: Wed Jan 31, 2024 11:16 pm Count icons and textlines... both the same. Problem is, you resized the fontsize and now you have to align the offsets in both online and offline lines in the script
OH CRAP thats too much work Ill just restore the font sizes
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Network related bash question

Post by Koentje »

:lol:

Here is the script with IP adresses.

Code: Select all

#!/bin/bash

# Placement of first image
x=1

# Offset of only the first hostname/ip
echo "\${voffset -16}"


while read -r line
do

     # Get hostname or ip address
     hostname=$(echo "$line" | awk '{print $1}')

     # Use this if you want to exclude a hostname or ip address.
     # You can make more of these lines with different hostnames/ip's.
     # Comment out if you don't want to exclude anything.
     #if [ "$hostname" = "router.asus.com" ]; then continue; fi
     #if [ "$hostname" = "192.168.1.104" ]; then continue; fi


     # Ping to see if online
     pvar=$(fping -q -c1 -t100 "$hostname" >/dev/null 2>&1; echo $?)
     if [ "$pvar" = "0" ]; then
      echo "\${image ./images/pc-online.png -p 1, $x -s 47x48}\${font Neon 80s:bold:size=16}\${voffset 14}\${goto 60}\${color red}$hostname\${font}"
      echo "\${goto 60}\${color 66FF00}Online!  \${color white}$(dig +short $hostname)"
     else
      echo "\${image ./images/pc-offline.png -p 1, $x -s 47x48}\${font Neon 80s:bold:size=16}\${voffset 14}\${goto 60}\${color 882200}$hostname\${font}"
      echo "\${goto 60}\${color 882222}Offline!  \${color 777777}$(dig +short $hostname)"
     fi

     # Placement of next image
     x=$((x+50))

done < <(arp | tail -n+2 | sort)
What fontsize do you want it to be?
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

Koentje wrote: Wed Jan 31, 2024 11:34 pm What fontsize do you want it to be?
That looks great as is! Thanks :D
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Network related bash question

Post by Koentje »

Here you go.. Completely customizable! :mrgreen:

networkpc2-v1.2.tar.gz
(8.5 KiB) Downloaded 18 times

options are:

Code: Select all

#
# Fontname for hostnames    ex. "Ubuntu Mono:bold:size=15"
fontname1="Neon 80s:bold:size=17"
#
# Fontname for 2nd text line   ex. "Ubuntu Mono:bold:size=10"
fontname2="Ubuntu Mono:bold:size=11"
#
# This is to offset the first/starting hostname  (can be negative nr)
voffhostfirst="-10"
#
# Vertical spacing between hostnames
voffhost="13"
#
# Horizontal spacing between image and  hostname
hoffhost="60"
#
#
# Vertical placement of first image  (can be negative nr)
vpix="10"
#
# Horizontal placement of all images  (can be negative nr)
hpix="1"
#
# Geometry of picture  ex. "45x45"
geopix="47x48"
#
# Horizontal spacing between online text and ip address
hoffip="10"
#
#
# Color hostname online  (RRGGBB or name like red, white, grey)
colhoston="red"
#
# Color hostname offline  (RRGGBB or name like red, white, grey)
colhostoff="882200"
#
# Color "online" text  (RRGGBB or name like red, white, grey)
coltxton="66FF00"
#
# Color "offline" text  (RRGGBB or name like red, white, grey)
coltxtoff="882222"
#
# Color ip adress online  (RRGGBB or name like red, white, grey)
colipon="white"
#
# Color ip adress offline  (RRGGBB or name like red, white, grey)
colipoff="777777"
#
#
# Exclude these ip/hostnames  ex. (192.168.1.1 router.asus.com)
# Hostnames/ips seperated by a space.
exclude=""
#
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Network related bash question

Post by Logansfury »

How would a title be added to this?

Id like the word Network at the top of the list
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Scripts & Bash”