Network related bash question
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Network related bash question
Hello everyone,
I want to see if I can manage to make a conky widget that displays the status of the computers in my network.
I know all my computers device names, local IP addresses, and mac addys. I wanted to make a little graphic widget that lists all the comps by name and presents either a red or green indicator to show if particular comp is online and available. How should I best go about this? Would setting up a script to send like a single ping every 1-5 mins to each comp on the network be realistic? What script could react to the returning data?
I honestly don't know if this is a basic or complicated ask >.<
Thanks for reading,
Logan
I want to see if I can manage to make a conky widget that displays the status of the computers in my network.
I know all my computers device names, local IP addresses, and mac addys. I wanted to make a little graphic widget that lists all the comps by name and presents either a red or green indicator to show if particular comp is online and available. How should I best go about this? Would setting up a script to send like a single ping every 1-5 mins to each comp on the network be realistic? What script could react to the returning data?
I honestly don't know if this is a basic or complicated ask >.<
Thanks for reading,
Logan
Re: Network related bash question
Conky script
Bash script
networkpc.conky
Code: Select all
conky.config = {
-- **********************************************************************
-- "Network PC"
-- **********************************************************************
background = false,
alignment = 'top_left',
gap_x = 10,
gap_y = 10,
minimum_width = 306,
minimum_height = 20,
draw_borders = false,
border_width = 0,
stippled_borders = 0,
default_color = 'white',
default_outline_color = 'white',
default_shade_color = 'black',
draw_graph_borders = true,
draw_outline = false,
draw_shades = false,
show_graph_scale = false,
show_graph_range = false,
double_buffer = true,
no_buffers = true,
out_to_console = false,
out_to_stderr = false,
extra_newline = false,
uppercase = false,
-- use_spacer = 'right',
-- format_human_readable = true,
pad_percents = no,
own_window = true,
own_window_class = 'conky-networkpc',
own_window_title = 'conky-networkpc',
own_window_type = 'dock',
own_window_transparent = true,
own_window_colour = '000000',
own_window_argb_visual = true,
own_window_argb_value = 255,
own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
use_xft = true,
xftalpha = 1,
font = 'Noto Sans:bold:size=9',
color0 = 'white',
color1 = '#EAEAEA',
color2 = '#FFA300',
color3 = 'grey',
update_interval = 1,
};
conky.text = [[
#
# Check if network PC is active
${font Noto Sans:bold:size=9}${voffset 0}${offset 1}${color2}NETWORKPC${execpi 15 ./ping-networkpc.sh}
#
#
]];
Bash script
networkpc.sh
Code: Select all
#!/bin/bash
# Single ip address or multiple ip addresses.
# Multiple ip addresses seperated by a space
ips=(192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.200 192.168.1.250 192.168.1.251)
for ip in "${ips[@]}"; do
pvar=$(fping -q -c1 -t100 $ip >/dev/null 2>&1; echo $?)
if [ "$pvar" = "0" ]; then
echo "\${goto 110}\${color white}$ip\${goto 220}\${color 66FF00}Online!"
else
echo "\${goto 110}\${color white}$ip\${goto 220}\${color FF4422}Offline!"
fi
done
Re: Network related bash question
I personally use the graphbar for this. So i can see on/offline for over 10 minutes and also ping in milliseconds.
Bar changes color if ping is low (green), average (grey), high (orange) and offline (red). You can even use domain names.
Bar changes color if ping is low (green), average (grey), high (orange) and offline (red). You can even use domain names.
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
HOLY CRAP!!
I just got back from walking the dog, sorry for the delay in response.
This is EXACTLY what I was wanting, a display of my home intranet comps with thier 192 local addys and indicators of on and offline.
I had actually just earlier finished a background image to put green or red indicators by:
Im grabbing all the scripts you have provided here to see how they look on my system
I may put some stuff on the 2nd monitor!
I just got back from walking the dog, sorry for the delay in response.
This is EXACTLY what I was wanting, a display of my home intranet comps with thier 192 local addys and indicators of on and offline.
I had actually just earlier finished a background image to put green or red indicators by:
Im grabbing all the scripts you have provided here to see how they look on my system
I may put some stuff on the 2nd monitor!
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
I have copied these two files, I have edited in my own intranet addys, separated by spaces, and I have chmod +x on the .sh file. When I fire up the .conky all I see is the word network, none of my IPs are listed.Koentje wrote: ⤴Wed Jan 31, 2024 6:50 pm Conky scriptnetworkpc.conky
Code: Select all
conky.config = { -- ********************************************************************** -- "Network PC" -- ********************************************************************** background = false, alignment = 'top_left', gap_x = 10, gap_y = 10, minimum_width = 306, minimum_height = 20, draw_borders = false, border_width = 0, stippled_borders = 0, default_color = 'white', default_outline_color = 'white', default_shade_color = 'black', draw_graph_borders = true, draw_outline = false, draw_shades = false, show_graph_scale = false, show_graph_range = false, double_buffer = true, no_buffers = true, out_to_console = false, out_to_stderr = false, extra_newline = false, uppercase = false, -- use_spacer = 'right', -- format_human_readable = true, pad_percents = no, own_window = true, own_window_class = 'conky-networkpc', own_window_title = 'conky-networkpc', own_window_type = 'dock', own_window_transparent = true, own_window_colour = '000000', own_window_argb_visual = true, own_window_argb_value = 255, own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager', use_xft = true, xftalpha = 1, font = 'Noto Sans:bold:size=9', color0 = 'white', color1 = '#EAEAEA', color2 = '#FFA300', color3 = 'grey', update_interval = 1, }; conky.text = [[ # # Check if network PC is active ${font Noto Sans:bold:size=9}${voffset 0}${offset 1}${color2}NETWORKPC${execpi 15 ./ping-networkpc.sh} # # ]];
Bash scriptnetworkpc.sh
Code: Select all
#!/bin/bash # Single ip address or multiple ip addresses. # Multiple ip addresses seperated by a space ips=(192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.200 192.168.1.250 192.168.1.251) for ip in "${ips[@]}"; do pvar=$(fping -q -c1 -t100 $ip >/dev/null 2>&1; echo $?) if [ "$pvar" = "0" ]; then echo "\${goto 110}\${color white}$ip\${goto 220}\${color 66FF00}Online!" else echo "\${goto 110}\${color white}$ip\${goto 220}\${color FF4422}Offline!" fi done
Schermafdruk van 2024-01-31 23-50-41.jpg
What must I do to activate this?
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
WOOT more stuff
I just did the install and the terminal bears out that I didn't have it previously, but now that its installed I have restarted the script and it still only displays the window title
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
Is a reboot necessary?
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
Code: Select all
logansfury@OptiPlex-5040:~$ cd .conky/Network\ Koentje
logansfury@OptiPlex-5040:~/.conky/Network Koentje$ ./networkpc.sh
${goto 110}${color white}192.168.0.101${goto 220}${color 66FF00}Online!
${goto 110}${color white}192.168.0.36${goto 220}${color 66FF00}Online!
${goto 110}${color white}192.168.0.174${goto 220}${color 66FF00}Online!
${goto 110}${color white}192.168.0.126${goto 220}${color 66FF00}Online!
${goto 110}${color white}192.168.0.235${goto 220}${color FF4422}Offline!
${goto 110}${color white}192.168.0.161${goto 220}${color 66FF00}Online!
logansfury@OptiPlex-5040:~/.conky/Network Koentje$
Re: Network related bash question
Do you have this in your conky script?
${execpi 15 ./ping-networkpc.sh}
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
I do
Code: Select all
# Check if network PC is active
${font Noto Sans:bold:size=9}${voffset 0}${offset 1}${color2}NETWORKPC${execpi 15 ./ping-networkpc.sh}
Re: Network related bash question
DUH!!Logansfury wrote: ⤴Wed Jan 31, 2024 8:39 pm logansfury@OptiPlex-5040:~/.conky/Network Koentje$ ./networkpc.sh
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
I never saw any scripts in the post for using that other one.
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
May I have the scripts for the graph please?
- Logansfury
- Level 6
- Posts: 1237
- Joined: Fri Oct 27, 2023 4:08 pm
- Location: Las Vegas NV, USA
Re: Network related bash question
oh OHHHHHHHHHHHH!! That file named networkpc.sh was supposed to be named ping-networkpc.sh all along wasn't it? I just changed the name and the widget is now display computer online status.Koentje wrote: ⤴Wed Jan 31, 2024 9:27 pmDUH!!Logansfury wrote: ⤴Wed Jan 31, 2024 8:39 pm logansfury@OptiPlex-5040:~/.conky/Network Koentje$ ./networkpc.sh
Far out!!
Re: Network related bash question
The graph can be downloaded from my website http://www.cobrasoft.nl/download/conky/pinggraph
Re: Network related bash question
I attached the one with the icons..
But you need to edit the
My host file looks like this:
But you need to edit the
/etc/host
file for this one. Add all hostnames and ip's.My host file looks like this:
Code: Select all
127.0.0.1 localhost
127.0.1.1 p3300lx
192.168.1.2 router2.asus.com
192.168.1.3 fritzbox
192.168.1.11 galaxy
192.168.1.22 camsung
192.168.1.101 p3300lx
192.168.1.102 mediapc
192.168.1.103 kodi
192.168.1.200 nas
192.168.1.250 ipcam-oprit1
192.168.1.251 ipcam-oprit2
192.168.1.252 ipcam-washok
192.168.1.253 ipcam-aanbouw
192.168.1.254 ipcam-shelby
# 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