473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Validating IP addresses in bash

docdiesel
297 Expert 100+
Hi all,

I've got a bash / shell script that has to validate an input whether it's an IP address or not. So far my code works as follows:

Expand|Select|Wrap|Line Numbers
  1.   MYCHECK=` echo ${IPADDR:0:15} | sed "s/[0-9]\{1,3\}//g" `
  2.  
  3. ## check if parameter was ip
  4. #
  5. if [ ${MYCHECK} = "..." ]; then
  6.   ..
  7. else
  8.   ..
  9. fi
  10.  
The script is working fine. In line 1 I'm simply replacing all numbers with {nothing}, so that all that remains are the three points. I know you could enter 999.999.999.999 and it wouldn't be a valid ip address, but that's OK for me as long as nobody is able to slip in a "rm -R /". ;-)

Now, my question is: did I miss something? Is it possible to get around this check? (Has been easy to write, so there must be something wrong...)

Regards, Bernd
Aug 31 '07 #1
1 4310
michaelb
534 Expert 512MB
This looks safe, unless you have a shell alias that associates some dot-numeric string with a malicious command.
Sep 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John | last post by:
What are the methods used in validating email addresses in Windows i.e what are the replacement for getmxrr? does anyone have an example? Thank you John
8
by: UndoMiel | last post by:
Hi, I am looking for a way to validate IP addresses using XML Schemas. The following is what i used: <xsd:simpleType name="IPType"> <xsd:restriction base="xsd:string"> <xsd:pattern...
46
by: TTroy | last post by:
Hi, I'm just wondering why people/books/experts say "the function returns a pointer to.." or "we have to send scanf a pointer to.." instead of "the function returns the address of.." or "we have...
2
by: Doug | last post by:
I'm a little confused by this functionality. It doesn't seem to be behaving like it should. I am using the following regular expression to validate email addresses:...
5
by: H.B. | last post by:
Hi, - Is there a function that can validate IP addresses? - Is there a function that can validate MAC addresses? Hugo
6
by: yochessyo | last post by:
Hi, I would like to validate email addresses. I am not interested to validate it with a regex expression but from the email server where the addresses are. I would like to query this server and...
1
by: cemcat | last post by:
Hello, We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to enter multiple e-mail addresses separated by semicolons. We need to validate that each individual e-mail address...
4
by: SAL | last post by:
I am using a RegularExpressionValidator control on my ASP page, and I have the ValidationExpression property set to "Internet E-mail Address". The email address is valiated when the user puts in a...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.