For Linux and Shell scripting.

Check IP format


#! /bin/bash

# check format of ip address
function iptest {
case “$*” in
“”|*[!0-9.]*) return 1;;
local IFS=.
set — $*
[ $# -eq 4 ] &&
[ ${1:-555} -le 255 ] && [ ${2:-555} -le 255 ] &&
[ ${3:-555} -le 255 ] && [ ${4:-555} -le 255 ]

if iptest $1; then
echo “IP format is okay”
echo “Wrong ip format”


[abdurahiman@49 sed]$ sh check_ip 192.168.1
Wrong ip format
[abdurahiman@49 sed]$ sh check_ip
IP format is okay
[abdurahiman@49 sed]$



3 thoughts on “Check IP format

  1. I tried it but it doesn’t work 😦

  2. Hi,

    Double quotes in these web-pages don’t work in the way it should be :(. I think it’s the problem of all html pages.

    Anyway, after you copy-paste the script, just edit double quotes (remove and then add again). Also, remove the minus (-) sign after *set* and then add two minus (-) signs instead. That as well gets wrong while copying.

    Try now and let me know how it goes. It should work for sure ;).

  3. hai, my site views mobile (nokia) wrong ip format?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s