LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-10-2010, 10:35 AM   #31
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16

just to let you know:
when i do ifconfig on PC this is what i get (this is only a sample):

eth0 Link encap:Ethernet HWaddr 02:7y:74:lA:9p:46
inet addr:10.20.8.254 Bcast:10.20.15.255 Mask:255.255.240.0
blah....blah.....
blah....blah.....
blah....blah.....
blah....blah.....
 
Old 05-10-2010, 10:44 AM   #32
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Code:
ifconfig eth0 | awk -F: 'NR==2{print $NF}'
I assume you can do the rest from here?
This should also give you a clue about the 4th line
 
Old 05-10-2010, 10:50 AM   #33
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Thanks for your quick reply.
i will do the rest & let you know if i hit a WALL!!!
 
Old 05-10-2010, 11:07 AM   #34
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Hi grail, the code

Quote:
ifconfig eth0 | awk -F: 'NR==2{print $NF}'
supposed to get the MASK Address? i tried it out by directing to a file & got nothing!!
i think i am doing something wrong???
 
Old 05-10-2010, 11:12 AM   #35
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Sorry My BAD....!! it is working
 
Old 05-10-2010, 01:02 PM   #36
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
when we do at the prompt

myhost> whatmask 255.255.192.0

---------------------------------------------
TCP/IP SUBNET MASK EQUIVALENTS
---------------------------------------------
CIDR = .....................: /18
Netmask = ..................: 255.255.192.0
Netmask (hex) = ............: 0xffffc000
Wildcard Bits = ............: 0.0.63.255
Usable IP Addresses = ......: 16,382

we get the above info.

so, I used your code & directed the result to a file called it maskfile. copy the whatmask in tmp& then use the following:

Quote:
ipbits= `/tmp/whatmask "maskfile" | grep "CIDR=."| awk -F/'{print $2}'
but it does not work. i want to get the CIDR value only so after insert it at the end of the 4th ip address of the FileA send it to the new file.

i believe i still need your help, thank you.
 
Old 05-10-2010, 06:57 PM   #37
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
Try this: http://tldp.org/LDP/abs/html/
 
Old 05-10-2010, 09:36 PM   #38
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Well off hand I would go with:
Code:
ipbits=$(whatmask 255.255.192.0 | awk -F: '/CIDR/{print $2}')
 
Old 05-10-2010, 10:18 PM   #39
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Hi grail thanks for your kind reply. i am searching how to feed subnetmask to "whatmask" program using a file. i will let you know once i found something.
thanks again for taking the time to help me.
 
Old 05-10-2010, 10:23 PM   #40
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Quote:
i am searching how to feed subnetmask to "whatmask" program using a file.
Why? Is this for your own education? It does not seem like it would be required to place in a file and then retrieve back again.
 
Old 05-10-2010, 10:41 PM   #41
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
If you recall we have this code:

Quote:
ifconfig eth0 | awk -F: 'NR==2{print $NF}'
where we output only the subnetmask from ifconfig, by sending subnetmask to a file, we can use it by "whatmask" program,
to get the CIDR notation. after add CIDR to the ip address of the 4th line of FileA.
At the end, to have ex.: 192.168.0.0/16.
so for each ifconfig (on each pc) i must come up with this format: $ip.$ip.0.0/$cidr, then the custom made script will be able to assign the right ip address to each PC. after according to their ip addresses they have different roles on the domain. So, right IP address is important.

Thanks for your attention.
 
Old 05-10-2010, 11:39 PM   #42
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Not sure whether you can pipe or should use command substitution as i do not have whatmask to experiment with, but one of these should do the trick:
Code:
ipbits=$(ifconfig eth0 | awk -F: 'NR==2{print $NF}' | whatmask | awk -F: '/CIDR/{print $2}')

#or

ipbits=$(whatmask $(ifconfig eth0 | awk -F: 'NR==2{print $NF}')| awk -F: '/CIDR/{print $2}')

#or if you want to be funky you could try

ipbits=$(ifconfig eth0 | awk -F: 'NR==2{print | "whatmask "$NF}' | awk -F: '/CIDR/{print $2}')
Let me know what works
 
Old 05-11-2010, 08:14 AM   #43
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Good Morning All,

tried grail's last command (the FUNKY ONE), made small change as followneeded space between whatmask & $NF)

Quote:
ipbits=$(ifconfig eth0 | awk -F: 'NR==2{print | "whatmask " " "$NF}' | awk -F: '/CIDR/{print $2}')
worked great. THANK YOU grail. Nice work.

Now, i must output only the IP address of the 4th line of my FileA & add the CIDR at the end of the IP addr. with no space.
to get something like: 192.168.0.0/$ipbits (so 192.168.23.65 must become 192.168.0.0)

FileA:
Quote:
#this a comment
#this a comment
#this a comment
hostname 192.168.23.65
hostname 10.18.13.253
hostname 10.18.16.253
hostname 177.23.56.58
#this a comment
anymore FUNKY code to do this???

Last edited by NetRock; 05-11-2010 at 08:23 AM.
 
Old 05-11-2010, 09:09 AM   #44
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
If you go back through the posts I think you will see we already covered how to do this (hint: NR variable means Number of Records)
 
Old 05-11-2010, 11:13 AM   #45
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
i tried this:

Quote:
awk -F: 'NR==4{print $NF}' input_file | awk {x=gensub(/([0-9]+\.[0-9]+\.).*/,"\\10.0","g",$2);if(!_[x])print x > "file"}'
but got error...!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GPG - encode file while manipulating output file name itmozart Linux - Newbie 2 10-03-2009 12:28 PM
Output Redirection - Trying to output to screen and file? helptonewbie Linux - Newbie 7 03-19-2009 07:05 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
why when redirecting output to a file any file extension seems to be fine? dr_zayus69 Linux - General 1 05-21-2005 04:09 AM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 07:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration