Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ 1 [2] >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Set network settings on boot, With a remastered DSL< Next Oldest | Next Newest >
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: May 28 2005,00:28 QUOTE

Quote (friedgold @ May 06 2005,16:12)
Does any one know how the best way to check if a string is a valid ip address?

[ -z "$(echo "$i" | awk '/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/')" ]

should check the string is in the form ###.###.###.### where the #'s are nos, but it doesn't rule out stuff like 999.999.999.999.

Here is a neat way I saw using the cut command to parse out the string:

Code Sample
#!/bin/bash
# pass the ip string as an argument to this script

if echo $1 | grep -q "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$"
then
   for i in 1 2 3 4
   do
       export dotpart=` echo $1 | cut -f $i -d '.' `
       if [ $dotpart -lt 0 -o $dotpart -gt 255 ]
       then
           echo "ip address was bad"
           exit 1
       fi
   done
   echo "ip address was good"
else
   echo "ip address was bad"
   exit 1
fi
exit 0
Back to top
Profile PM 
Fallen Kell Offline





Group: Members
Posts: 21
Joined: May 2005
Posted: May 31 2005,15:02 QUOTE

Hey, I found my problem, well most of it anyway. This is really nice, since I have to find a way to get this to work with a frugal install and need network to come up automatically.

I will probably do some tweaking, but it looks good. Thanks for doing most of the hard work.
Back to top
Profile PM 
6 replies since May 05 2005,13:14 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ 1 [2] >/
reply to topic new topic new poll
Quick Reply: Set network settings on boot

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code