Finding if my IP address belongs in a Class C group

I need help with a tcl code. I have a variable "myIP" which reads IP address from socket. How do I use regex to find out if it belongs to a group for e.g., 50.65.75.240/28 or 50.65.75.128/25 etc.

You don't tell us the OS and version, which makes this pretty tricky because they are all slightly different when working at this level. Have a look at the output from netstat -nr and perhaps ifconfig -a

Do either of those give you what you need? Further to that, have a read of the netstat and ficonfig manual pages.

You will need to give us more detail to be able to suggest good solutions.

Robin

I don't think you can do this with a regex. With arithmetic evaluation in bash you could try

grIP=50.65.75.240/28
myIP=50.65.75.243
IFS="."
G=0
for i in ${grIP%/*}; do ((G=(G<<8)+i)); done
M=0
for i in ${myIP%/*}; do ((M=(M<<8)+i)); done
echo $(( (M-G > 0) * (M-G < 2**(32-${grIP#*/})) ))