LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-11-2022, 06:59 AM   #1
NSH
LQ Newbie
 
Registered: Mar 2022
Location: cph 128.0.73.54
Distribution: Linux mint 20
Posts: 8

Rep: Reputation: 0
Ip scanner script no worky work


Hi
I'm trying to understand why this bash script
<CODE>

#!/bin/bash

is_alive_ping()
{
ping -c 1 $1 > /dev/null
[ $? -eq 0 ] && echo Node with IP: $i is up.
}

for i in 192.168.2.{1..255}
do
is_alive_ping $i & disown
done
exit

</CODE>

dosn't return anything as it does in the the tutorial

<link> https://duckduckgo.com/?q=bash+scrip...%3DGtovwKDemnI </link>
at 1:00:00

Don't understand ip protocols that well.

Last edited by NSH; 04-11-2022 at 07:02 AM.
 
Old 04-11-2022, 07:50 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
I did not watch the video.

What is your LAN IP address network? You can find out by looking at the output of the command:
ip a

Under the section starting with 2: like
Code:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d9:b9:26 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.224/24 brd 192.168.1.255
The IP address is 192.168.1.244 and the network is 192.168.1.1 - 192.168.1.255, the loop should be
Code:
for i in 192.168.1.{1..254}
192.168.1.255 is the broadcast address and not assigned to a device. If yours is not /24 you can search for a IPv4 calculator to figure out your subnet. If it is an IPv6 address then the script needs to be changed a bit.
 
1 members found this post helpful.
Old 04-11-2022, 11:36 AM   #3
NSH
LQ Newbie
 
Registered: Mar 2022
Location: cph 128.0.73.54
Distribution: Linux mint 20
Posts: 8

Original Poster
Rep: Reputation: 0
Cool! find an inet adress starting with 100. Thank you.

Last edited by NSH; 04-11-2022 at 11:56 AM.
 
Old 04-11-2022, 12:27 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
Quote:
inet 100.xx.xx.xx/21
Your IP address is 100.xx.xx.xx with a 21 subnet which means the valid IP addresses are:
100.xx.xx.1 - 100.xx.xx.254 for a possible number of 2046 hosts.

One way to iterate the entire range would be to use two loops.
Code:
for x in 100.xx.{xx..yy}; do
  for y in {0..255}; do

  done
done
Using the loops as posted will ping some invalid addresses but it is the quickest. I did not watch the video and I'm not sure what the ultimate goal you are trying to achieve but some devices are configured to ignore icmp requests and I would be annoyed if I discovered someone trying to constantly ping me on my network.

Last edited by michaelk; 04-11-2022 at 12:37 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slack 9.1, kernel 2.6.3-r3, Epson Scanner and libusb no worky for Joe user. finegan Slackware 1 02-16-2004 12:49 AM
slack 9 mysql no worky Finlay Slackware 2 08-16-2003 10:22 AM
root=mozilla runs, user=no worky the_tflk Linux - Software 5 07-13-2003 04:54 AM
MikMod no worky :( NightShade737 Linux - Software 0 07-05-2003 08:44 AM
DNS no worky Nexty Linux - Networking 6 09-06-2002 12:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration