I would like to apply a netmask to an arbitrary IP in a bash/dash script
(e.g. apply 255.255.255.0 to 173.10.3.155 to get 173.10.3.0). Is there any
easy way to do that without taking the IP apart, doing 4 operations and
reassembling the results?
--
Dazed_75 a.k.a. Larry
The spirit of resistance
On Wednesday, October 26, 2011 21:49:40 Dazed_75 wrote:
> I would like to apply a netmask to an arbitrary IP in a bash/dash script
> (e.g. apply 255.255.255.0 to 173.10.3.155 to get 173.10.3.0). Is there any
> easy way to do that without taking the IP apart, doing 4 operations and
> reassembling t
well, an IP4 address is just an unsigned int32, and a netmask is just the
number of bits to keep...
you could turn the dotted notation into an int32, then mask off the proper
bits, then translate back to the dotted notation.
Or you could use Python for the script and use the ip address library i
I'm not trying to configure network interfaces, I am actually extracting the
current IP address and netmask FROM ifconfig. What I want to do is apply
the netmask to the current IP in order to update /etc/dnsmasq.conf's value
to the DHCP range it should proxy for in a portable PXE server.
IOW, the
Thanks Josef, I was hoping there was a way to avoid the manipulation work.
I have never used Python though I have looked at some. I saw 3 .py files
and release notes in the download. I saw no readable description of the
contents/functionality and more unfamiliar code I didn't want to read.
proba
There is an android app that does the math. But that's all I got.
On Oct 27, 2011 12:38 AM, "Dazed_75" wrote:
> Thanks Josef, I was hoping there was a way to avoid the manipulation work.
>
> I have never used Python though I have looked at some. I saw 3 .py files
> and release notes in the downl
On 10/26/2011 09:49 PM, Dazed_75 wrote:
I would like to apply a netmask to an arbitrary IP in a bash/dash script
(e.g. apply 255.255.255.0 to 173.10.3.155 to get 173.10.3.0). Is there
any easy way to do that without taking the IP apart, doing 4 operations
and reassembling the results?
--
Dazed_
Is this along the lines of what you are looking for?
You'll need to install ipcalc first
#!/bin/bash
TEMP=$(ifconfig eth0 |grep 'inet addr')
ADDRESS=$(echo $TEMP|cut -f2 -d:)
ADDRESS=${ADDRESS% *}
MASK=$(echo $TEMP|cut -f4 -d:)
NETTEMP=$(ipcalc $ADDRESS/$MASK|grep Network)
NETTEMP=${NETTEMP#*: }
Thanks Eric. Those are what I was going to use before I had the thought
that someone might know of an already built function I could use rather than
me taking the IP and netmask apart, applying those, and reassembling the
IPrange. I suppose I've already wasted more time than I would have saved.
:
Brian's ipcalc looks like it might simplify things a bit. Nice.
On 10/27/2011 10:57 AM, Dazed_75 wrote:
Thanks Eric. Those are what I was going to use before I had the thought
that someone might know of an already built function I could use rather
than me taking the IP and netmask apart, applyi
Yep, I just finished playing with it. My result I will put in the script
should be:
RANGE=`ipcalc $MYIP $MYMASK | grep Network | cut -d' ' -f 4 | cut -d/ -f 1`
On Thu, Oct 27, 2011 at 11:13 AM, Eric Shubert wrote:
> Brian's ipcalc looks like it might simplify things a bit. Nice.
>
>
> On 10/
Larry wrote:
> I would like to apply a netmask to an arbitrary IP in a bash/dash script
> (e.g. apply 255.255.255.0 to 173.10.3.155 to get 173.10.3.0). Is there any
> easy way to do that without taking the IP apart, doing 4 operations and
> reassembling the results?
I know you said without disass
I've never had a need to do any bit twiddling in bash... thanks for this
solution, It was very educational.
Brian Cluff
On 10/27/2011 11:43 AM, Dale Farnsworth wrote:
Larry wrote:
I would like to apply a netmask to an arbitrary IP in a bash/dash script
(e.g. apply 255.255.255.0 to 173.10.3.1
Agreed! Certainly more elegant than anything I might have done today.
Maybe back in the days when I made a living doing this stuff, but ...
Hmmm, I need to start saving some of these gems!
Thanks Dale.
On Thu, Oct 27, 2011 at 4:19 PM, Brian Cluff wrote:
> I've never had a need to do any bit t
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Have you looked at ipcalc? It does some really cools stuff and can be
scripted.
On 10/27/2011 06:19 PM, Brian Cluff wrote:
> I've never had a need to do any bit twiddling in bash... thanks for this
> solution, It was very educational.
>
> Brian Cluf
Yes Thomas. If you look back a few messages in the thread, you will see
that not only was it suggested, but that is how I solved my need. Thank you
though.
On Fri, Oct 28, 2011 at 1:28 PM, tho...@redhat.com wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Have you looked at ipcalc?
16 matches
Mail list logo