LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-11-2013, 10:39 AM   #1
marmur18
LQ Newbie
 
Registered: Sep 2013
Posts: 3

Rep: Reputation: Disabled
IP mask using cat pipe sed


All,

Would it be possible to mask ip information lets say 192.168.1.1 to xxx.xxx.1.1 from the terminal?


Have been attempting variations of:

cat /etc/sysconfig/iptables | sed 's/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.\b/xxx.xxx./g'

tried ' and ", sed -i, sed -e, /g or global and without...
but it doesn't appear to be changing the output.

Does it have to output to a file? Was hoping to throw this in an sh and email the output without having to > some.txt and then rm'ing it as this adds alerts from AIDE

Thoughts?

Thanks in advance
 
Old 09-11-2013, 11:08 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
google(ip address regex)[3] = http://answers.oreilly.com/topic/318...r-expressions/

google(email in commandline)[1] = http://www.simplehelp.net/2008/12/01...-command-line/

Last edited by schneidz; 09-11-2013 at 11:16 AM.
 
Old 09-11-2013, 11:42 AM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Try this:
Code:
sed -r 's/[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9](\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9])/xxx.xxx\1/g'
 
Old 09-11-2013, 12:34 PM   #4
marmur18
LQ Newbie
 
Registered: Sep 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks all

got it with this:

cat /etc/sysconfig/iptables | sed -r 's/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\./xxx.xxx.xxx./g'

output all ipv4's to xxx.xxx.xxx.1

or

cat /etc/sysconfig/iptables | sed -r 's/[0-9]{1,3}\.[0-9]{1,3}\./xxx.xxx.xxx./g'

output all ipv4's to xxx.xxx.1.1

can be used to obfuscate all sorts of logs and files, very nice

wonder if I can place this on the mail relay to edit all outgoing email subjects and bodies.

now to figure out the ipv6 version of this for ipv6tables.

Thanks again
 
Old 09-11-2013, 12:37 PM   #5
marmur18
LQ Newbie
 
Registered: Sep 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
oops for the second example:

cat /etc/sysconfig/iptables | sed -r 's/[0-9]{1,3}\.[0-9]{1,3}\./xxx.xxx.xxx./g'

should have been:

cat /etc/sysconfig/iptables | sed -r 's/[0-9]{1,3}\.[0-9]{1,3}\./xxx.xxx./g'
 
  


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
[SOLVED] cat: write error: Broken pipe MikeyCarter Linux - Software 4 06-19-2013 02:26 PM
Cat and Sed Command Help. vidyashankara Linux - General 22 06-23-2006 01:32 PM
Character conversion combining cat and pipe lda_ga Linux - General 5 08-04-2005 02:45 PM
less, cat, sed or what ebasi Linux - Software 8 07-28-2004 03:26 AM

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

All times are GMT -5. The time now is 05:41 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