#!/bin/sh belongs_network () { addr=$1 network=$2 netaddr=`echo $network | cut -d / -f 1` netcdr=`echo $network | cut -d / -f 2` a1=$(echo "$addr" | cut -d . -f 1) a2=$(echo "$addr" | cut -d . -f 2) a3=$(echo "$addr" | cut -d . -f 3) a4=$(echo "$addr" | cut -d . -f 4) n1=$(echo "$netaddr" | cut -d . -f 1) n2=$(echo "$netaddr" | cut -d . -f 2) n3=$(echo "$netaddr" | cut -d . -f 3) n4=$(echo "$netaddr" | cut -d . -f 4) ares=$((($a1*256*256*256+$a2*256*256+$a3*256+$a4)>>(32-$netcdr))) nres=$((($n1*256*256*256+$n2*256*256+$n3*256+$n4)>>(32-$netcdr))) if [ $ares -eq $nres ] ; then return 0 else return 1 fi } if belongs_network 10.208.103.255 10.208.128.0/17; then echo "belongs" else echo "does not belong" fi
Показаны сообщения с ярлыком IP. Показать все сообщения
Показаны сообщения с ярлыком IP. Показать все сообщения
пятница, 13 октября 2017 г.
Does ip belong to network?
It's so easy to check if IP belong to network... Until you start doing this in shell. I've tried and finally got this. This version works in bash, dash and ksh...
Good enough for me, but perhaps it could be optimized a bit to avoid cut usage.
Our function gets two parameters - ip address and network in address/netmask format. In fact we compare IPaddress & netmask and IPnetwork & netmask.
воскресенье, 24 октября 2010 г.
Is our favourite government fucken crazy?
It's not a dream of some moron, it's real bill. Hail to Mr. Mikhalkov and Mr. Putin! It seems some ancient morons created quite idiotic law...
1) We have to pay 1 % from the cost of CD/DVD disks, Hard drives and other "data stores" (материальные носители) for some organization which distribute this money among authors.
2) This organization is not even formed.
3) And what if I use my flash stick to backup my home directory or to carry my own presentation or even to setup Ubuntu or FreeBSD on it?
5) And if I've paid this taxes in the store, could I freely distribute copies of some good film (not Mikhalkov's one, but something really interesting)? It seems not. Some contradiction...
If I buy a new flash stick, it will be more expensive by 10-30 roubles (about 30 cents - $1). Not much. But if we summ all these money, we have a good amount to steal.
Hail to our government! The next thing we need is a tax on the amount of trees in the garden. And these taxes we will spread between.... let's suppose... agronomists (they created seeds for you... You might have bought these seeds but who cares).
1) We have to pay 1 % from the cost of CD/DVD disks, Hard drives and other "data stores" (материальные носители) for some organization which distribute this money among authors.
2) This organization is not even formed.
3) And what if I use my flash stick to backup my home directory or to carry my own presentation or even to setup Ubuntu or FreeBSD on it?
5) And if I've paid this taxes in the store, could I freely distribute copies of some good film (not Mikhalkov's one, but something really interesting)? It seems not. Some contradiction...
If I buy a new flash stick, it will be more expensive by 10-30 roubles (about 30 cents - $1). Not much. But if we summ all these money, we have a good amount to steal.
Hail to our government! The next thing we need is a tax on the amount of trees in the garden. And these taxes we will spread between.... let's suppose... agronomists (they created seeds for you... You might have bought these seeds but who cares).
Подписаться на:
Сообщения (Atom)