Bash script to calculate subnet address from IP and netmask

An area of the forum to discuss router binaries (utilities and applications that run on routers) etc.
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4772
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Thu Dec 06, 2007 7:12 pm

mstombs wrote:Exclusive OR doesn't seem to work...

BUT I have reduced your Bitwise OR to do the original function I wanted in a couple of unintelligible lines for shoto to gawp at!

Code: Select all

l="${IP%.*}";r="${IP#*.}";n="${NM%.*}";m="${NM#*.}"
subnet=$((${IP%%.*}&${NM%%.*})).$((${r%%.*}&${m%%.*})).$((${l##*.}&${n##*.})).$((${IP##*.}&${NM##*.}))
Consider it suitable Gawped At :notworthy: :thumb:
Jim

.....I'm Sorry But I Can't Do That Dave.....
User avatar
biro
RouterTech Team
RouterTech Team
Posts: 1274
Joined: Wed Jan 25, 2006 10:03 pm
Location: Letchworth Garden City, ENGLAND
Contact:

Post by biro » Fri Dec 07, 2007 5:40 pm

mstombs wrote:Exclusive OR doesn't seem to work...
XOR doesn't appear to be implemented on the router :!:
Not that it matters much as I got the logic / maths wrong. Appears more complicated than I thought, should still be possible to do it but not by simple logic.
mstombs wrote:BUT I have reduced your Bitwise OR to do the original function I wanted in a couple of unintelligible lines for shoto to gawp at!

I did it the long way as easier to understand without #comments everywhere ! Still had Shoto 'Bashing' his head though :twisted:
ImageImageImage
All my posts on RouterTech.org are Copyright RouterTech.org
G'Day Laura
mstombs
RouterTech Team
RouterTech Team
Posts: 3753
Joined: Wed Jan 10, 2007 11:54 pm

Post by mstombs » Fri Dec 07, 2007 6:03 pm

hehe shoto's comments make it all worth while - and the code is now in my version of the half bridge script! I don't need the second challenge - don't waste any time! NOT OR gets closer, but I can't see a way to do it except by iteration - testing that the subnet of each is same against a one of 32 candidates!
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12064
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Fri Dec 07, 2007 6:48 pm

biro wrote:
mstombs wrote:Exclusive OR doesn't seem to work...
XOR doesn't appear to be implemented on the router :!:
Perhaps something that needs to be switched on in the "ash" shell? I don't see anything in the build configuration file that could do this. Perhaps you might want to try the "bash" shell in the repository to see whether it would work there?
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4772
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Fri Dec 07, 2007 7:03 pm

mstombs wrote:hehe shoto's comments make it all worth while...
I Live to Serve :lol:
Jim

.....I'm Sorry But I Can't Do That Dave.....
Post Reply