ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: "Pavel S. Khmelinsky" <hmepas@yauza.ru>
To: community@altlinux.ru
Subject: Re: [Comm] script for checking if ip address is from network/len
Date: Sun, 19 Oct 2003 03:15:00 +0400
Message-ID: <3F91C974.4010803@yauza.ru> (raw)
In-Reply-To: <3F91BD3C.6030606@pisem.net>

Borovoy M. wrote:
> Pavel S. Khmelinsky пишет:
> 
>> Может кто подскажет простой способ из скрипта узнать пренадлежит ли ip 
>> адресс сети заданной в виде network/len. Понятно что можно и самому 
>> написать, но такое скорее всего уже есть. Хорошо бы либо модуль под 
>> перл, либо программку консольную ;)
> 
> 
> Посмотри man ipcalc, может поможет.
> Например
> $ ipcalc --network 192.168.123.1 255.255.224.0
> NETWORK=192.168.96.0

Ндя, чего-то я совсем забыл про это утилитку, спасибо большое что 
напомнили. Набросал не большую программку с ее использованием, 
если кому интересно:
----------------------------------------------------------------
#!/bin/bash
ip=$1
net=`echo $2 | perl -ne'/(\S+)\/\S+/;print $1;'`
len=`echo $2 | perl -ne'/\S+\/(\S+)/;print $1;'`

if test `ipcalc -n $ip/$len | sed 's/NETWORK=//'` = $net ; then
         echo IS_IN
fi
----------------------------------------------------------------

Вроде работает
$ ./iptest 82.148.25.128 82.148.25.64/26

$ ./iptest 82.148.25.127 82.148.25.64/26
IS_IN

$ ./iptest 82.148.25.64 82.148.25.64/26
IS_IN

$ ./iptest 82.148.25.65 82.148.25.64/26
IS_IN

$ ./iptest 82.148.25.255 82.148.25.64/26


Вот правда перловые regex я знаю много лучше того что в posix 
поэтому везде пользуюсь перлом что в данном случае не совсем 
оправданно, так что лучше наверное с использованием tr 
переписать, но мне чего-то лень в man 7 regex разбираться.

Михаил, еще раз спасибо.



  reply	other threads:[~2003-10-18 23:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-18 19:40 Pavel S. Khmelinsky
2003-10-18 22:22 ` Borovoy M.
2003-10-18 23:15   ` Pavel S. Khmelinsky [this message]
2003-10-18 23:40     ` Borovoy M.
2003-10-21  2:01 ` Pavel N.Solovyov
2003-10-21 10:30   ` Pavel S. Khmelinsky
2003-10-22  4:48     ` Alexey I. Froloff
2003-10-22 10:27       ` [JT]Re: " Pavel N.Solovyov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F91C974.4010803@yauza.ru \
    --to=hmepas@yauza.ru \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git