LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2017, 06:59 AM   #16
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274

If it was that difficult: I would simply try to execute ping.
Code:
If ping does not receive any reply packets at all it will exit with code 1.
If a packet count and deadline are both specified,
and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1.
On other error it exits with code 2.
Otherwise it exits with code 0.
This makes it possible to use the exit code to see if a host is alive or not.
 
Old 07-18-2017, 08:44 AM   #17
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Original Poster
Rep: Reputation: Disabled
The finality is not to check if ip is active but if ip is correct .
And without even mention that you are unable to ping a subnet like 192.168.1.1/24

However , i already fixed everything .

Here it is the code in bash with check if ip is between 0.0.0.0/0-255.255.255.255/32

Quote:
#!/bin/bash
function ckf () {
st="0"
tr "." "\n" <tmp >tmp1
splt=$(cat tmp1 | tr "." "\n")

for nmb in $splt
do

if [[ "$nmb" -ge "0" ]] && [[ "$nmb" -le 255 ]]
then
st=$((st+1))
if [ $st == "4" ]
then
ok=`cat tmp`
echo "Valid Ip : $ok"
fi
else
if [ $st -lt "4" ]
then
ok=`cat tmp`
echo "Invalid IP : $ok"
exit 1
fi
fi

done

rm -f tmp >/dev/null 2>&1
rm -f tmp1 > /dev/null 2>&1

}
echo -ne "Enter IP or IP range : ";tput sgr0
read ips
echo $ips > tmp
ip="$ips"
if [[ $ip =~ "/" ]]
then
chk="/"
chk1=`grep -o $chk <<< "$ip" | wc -l`
if [ $chk1 != 1 ]
then
echo "Invalid IP"
exit 1
else
sub=`cat tmp | cut -d "/" -f 2`
if [[ ! $sub =~ ^[^A-Za-z]+$ ]]; then
echo "Invalid IP"
exit 1
else
if [ $sub -lt "0" ]
then
echo "Invalid IP"
elif [ $sub -gt "32" ]
then
echo "Invalid IP"
exit 1
else
ipo=`cat tmp | cut -f1 -d "/"`
ckf
fi
fi
fi
else
echo $ips > tmp
ckf
fi
Basically almost every code can be done in bash programming , the problem is the amount of options that must be written .
It is almost the same thing as you using a plugin or active x controller in C or VB , you can do what the activex is doing by hand , the difference is the amount of code that must be written to contemplate that activex options .

Last edited by pedropt; 07-18-2017 at 08:52 AM.
 
Old 07-19-2017, 03:15 AM   #18
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,144

Rep: Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308
Another difference is speed; sysvinit is very slow running successive bash scripts by comparison with init-ng or systemd, or multithreaded binaries. What I would call intermediate languages (perl, python, etc.) are in the middle. Assembler can be difficult to code, especially as you increase in system complexity, but it's hellish fast.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
valid packet returning to INPUT after going through INVALID chain vincix Linux - Networking 1 06-09-2017 12:01 AM
[SOLVED] Bash user input valid then continue powerplyer Linux - Newbie 9 02-10-2015 04:56 AM
[SOLVED] Firewall up & working; need input & advice on configuration. lupusarcanus Linux - Newbie 1 12-22-2009 05:45 AM
syslog-ng & subnet filters koncept Linux - Software 5 05-23-2007 03:38 PM
how to detect which networkaddress, gateway, subnet on network without dhcp deadeyes Linux - Wireless Networking 2 03-02-2007 01:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 AM.

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