Finding if my IP address belongs in a Class C group


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding if my IP address belongs in a Class C group
# 1  
Old 04-18-2014
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.
# 2  
Old 04-22-2014
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
# 3  
Old 04-22-2014
I don't think you can do this with a regex. With arithmetic evaluation in bash you could try
Code:
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#*/})) ))

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Challenge in finding listing class method and its number of code lines

there are about 300 objectivec .m files and I need to print each file name and its method and number of lines inside the method there is a sample perl files that do perl brace matching... (0 Replies)
Discussion started by: steve32001
0 Replies

2. UNIX for Dummies Questions & Answers

Finding the Group Owner Name

Hi all, How can i find the group owner name...??? Thanks (4 Replies)
Discussion started by: mansahr143
4 Replies

3. Linux

Quota issue on user belongs to multiple Group

I have setup a group quota for better disk usage. What i am doing is to setup a quota with Samba share. I created user1,user2 and group project1 which belongs to /home/project1 dir. Quota is implemented on project1 group to write 100 MB on this share and This is working fine if a user1 and user2... (3 Replies)
Discussion started by: sunnysthakur
3 Replies

4. Programming

Printing class address!

Hello everyone, I have this code which prints the address of the object of a class....bt. what if I want to print the address of the class? #include <iostream.h> class har{ }; int main() { har a; cout<<(&a); } I would really appreciate if someone can help! Thanks!!!!! (1 Reply)
Discussion started by: mind@work
1 Replies

5. Shell Programming and Scripting

Finding an email address

Hi all, I have a file with X number of lines. Somewhere within each line will be an email address following the format: <telephone_number>@domain.net Each line is not a set length and there are no delimiters to work with. I want to write a script that extracts the telephone number... (3 Replies)
Discussion started by: mandriver
3 Replies

6. UNIX for Dummies Questions & Answers

Finding an IP address

Using either % nslookup www.computerhope.com or % host www.computerhope.com Is there a way to single out only the IP address and not all the other information that these commands return by using the options or something of this nature. For Example I would like to do this Echo... (1 Reply)
Discussion started by: slim1509
1 Replies

7. Shell Programming and Scripting

How to check if a user belongs to a group (KSH)?

Hi all, How can I check if a particular user id belongs to a group? (ie. how to check if the current user `whoami` is part of the a certain group? do i use the group name of group id?) Thanks in advance (2 Replies)
Discussion started by: rockysfr
2 Replies

8. UNIX for Dummies Questions & Answers

Finding IP address of the workstation

Hi, I have the following requirement. I want to configure in the .profile file of my user id in such a way that it loads a particular set of command when i log in from a particular machine and another set when i log into the server from a different machine. What is the command to get the... (1 Reply)
Discussion started by: Vijay Srinivasa
1 Replies

9. Shell Programming and Scripting

Finding the group to which a user belongs

Is there any command to find to which group u ser belongs (3 Replies)
Discussion started by: radhika03
3 Replies

10. UNIX for Dummies Questions & Answers

Finding LocalHost IP Address

I am writing a program that need to be run on several machines. I am running UNIX and wanted to know if there is a command similar to ipconfig (in DOS) that would return the IP Address of the machine that I am working on. (Not just the loopback address of 127.0.0.1). (1 Reply)
Discussion started by: hazard0007
1 Replies
Login or Register to Ask a Question