This question already has answers here:
Remove everything except a certain pattern
(4 answers)
Can't use ^ to say "all but"
(4 answers)
Closed 2 years ago.
There are thousands more like below lines in a txt file.
I want to only keep the ip addresses with their subnet masks.
This regex works fine: (\d+\.\d+\.\d+\.\d+)(/[0-9]+)
iptables -A INPUT -s 2.16.19.0/24 -j DROP
iptables -A INPUT -s 2.16.178.0/23 -j DROP
iptables -A INPUT -s 2.16.220.0/24 -j DROP
iptables -A INPUT -s 2.16.222.0/23 -j DROP
iptables -A INPUT -s 2.18.80.0/23 -j DROP
Related
On the terminal I can do something like
echo <password> | sudo -S ping www.google.com -c 3
but I am not sure how I can bring this within the c++ code using boost process.
bp::child(bp::search_path("ping"),"www.google.com -c 3",bp::std_out << output)
this works perfectly fine, but when I try to do something like
bp::child(bp::search_path("echo"),"password","|","sudo -S ping www.google.com -c 3",bp::std_out << output)
it gives an error.
I tried using bp::search_path("sh") to run the shell and pass the command, but this also gives and error saying cannot execute binary executables.
Any help will be really appreciated!
The security remarks to your question are fair. But, I can assume that what you are trying to do should look like this:
bp::child(bp::search_path("/usr/bin/bash"),"-c 'echo <password> | sudo -S ping www.google.com -c 3'",bp::std_out << output)
Sending a pcap file on port 0. I get the following error. Any fix would be appreciated!
The command used is:
sudo ./app/x86_64-native-linuxapp-gcc/pktgen -c 0X01 -n 1 --file-prefix=pg -w 4:00.1 -- -m 1.0 -T -P -s 0:~/Downloads/bigFlows.pcap
There are 2 obvious reasons for the failure.
Number of CPU cores for pktgen to work is 1 + number of ports in use
you have extra argument in comamnd executed in pktgen.
Checking the link, it show the command used is sudo ./app/x86_64-native-linuxapp-gcc/pktgen -c 0X01 -n 1 --file-prefix=pg -w 4:00.1 -- -m 1.0 -T -P -s 0:[~/Downloads/bigFlows.pcap]. You should not sue [] instead use 0:actual path to pcap.
Note: #SaifUllah during the live debug both core and pcap were show cased for you.
How do I correctly write this in a Windows Powershell? Coming from macOS, I have some problems in understanding what it is wrong with this:
pp -u -g -o Executable -f Bleach="^(AAA_|BBB_|MainScript)" MainScript.pl
The regular expression to be passed to the option -f (filter) is not accepted and fires all sort of errors (command not recognized, and so on, no matter as I try to change it). On a Unix system it works just fine.
Escape character for Powershell is `.
Something like this could work:
pp -u -g -o Executable -f Bleach=`"`(AAA_`|BBB_`|MainScript`)`" MainScript.pl`
This question already has answers here:
Escaping in makefile
(2 answers)
Closed 6 years ago.
I try to do a replace with following perl command:
perl -C -p -i -e 's/([\?\.\!])\n/$1 /g' html/數14.html
The result is fine when I call it from the command line. When I call it from within a Makefile it doesn't work. Apparently the $1 is interpreted as shell variable.
In the Makefile it looks like this:
數14.html: 數14.adoc 40_2064_Im\ Strand-Appartment.adoc 41_2064_Ein\ Plan.adoc 42_1915_In\ einer\ Suppenküche.adoc
asciidoctor -D html parts/數14.adoc
perl -C -p -i -e 's/([\?\.\!])\n/$1 /g' html/數14.html
How can I have normal regexp behaviour here?
Makefiles always interpret $ sequences before executing commands, disregarding any quoting. In order to escape $ in a Makefile, write it as $$ - that will result in a single $ in the command.
I've hit a bit of a stumper (for me). I'm attempting to insert two newline characters into the RHEL5 /etc/sysconfig/iptables file during our server build process (using kickstart post-installation scripts).
The specific sed command is:
${SED} -i "/-i lo/ a\
\n\n#Trusted Traffic\n-A INPUT -s 10.153.156.0/25,10.153.174.160/27 -d ${MGTIP} -m state --state NEW -j ACCEPT\n\n#Remote Access\n-A INPUT -s 10.120.80.0/21,10.152.80.0/21,10.153.193.0/24,172.18.1.0/24,${MGTNET}/${NUMBITS} -d ${MGTIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n#Backups\n-A INPUT -s 10.153.147.192/26 -d ${BKPIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n" ${IPTABLES}
This is actually part of a larger script. ${SED}and ${IPTABLES} are already set to the necessary values.
All of the newlines work with the exception of the first two. Or, more accurately, the second of the first two. Even the last two newlines after ACCEPT work. What happens with the first two newlines is that the first works, creating a newline after matching the iptables entry which contains -i lo. The second, however, simply inserts a literal 'n' prior to the #Trusted Traffic text.
It ends up looking like
(snip)
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
n#Trusted Traffic
-A INPUT (snip)
I've tried various methods of ensuring the second newline is inserted. I've used two blank lines instead of \n\n. I've used two newline characters on separate lines, I've used \\n\\n. Everything I've tried so far results in the same outcome: A literal 'n' being inserted instead of a second newline.
Does sed simply not work with two newline characters at the beginning of appended text? Is there a way to make this work that I'm simply ignorant of?
I don't see why it's not working either, but you can do this also with the substitute option instead of append:
${SED} -i "s%-i lo.*%&\n\n#Trusted Traffic\n-A INPUT -s 10.153.156.0/25,10.153.174.160/27 -d ${MGTIP} -m state --state NEW -j ACCEPT\n\n#Remote Access\n-A INPUT -s 10.120.80.0/21,10.152.80.0/21,10.153.193.0/24,172.18.1.0/24,${MGTNET}/${NUMBITS} -d ${MGTIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n#Backups\n-A INPUT -s 10.153.147.192/26 -d ${BKPIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n%" ${IPTABLES}
Interesting, I would have thought that one of your attempted solutions would work, but I am seeing the same behavior. Here is one potential solution:
${SED} -i -e "s/-i lo.*/\0\n\n/" -e "// a\
#Trusted Traffic\n-A INPUT -s 10.153.156.0/25,10.153.174.160/27 -d ${MGTIP} -m state --state NEW -j ACCEPT\n\n#Remote Access\n-A INPUT -s 10.120.80.0/21,10.152.80.0/21,10.153.193.0/24,172.18.1.0/24,${MGTNET}/${NUMBITS} -d ${MGTIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n#Backups\n-A INPUT -s 10.153.147.192/26 -d ${BKPIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n" ${IPTABLES}
This works by first appending the two newlines to the end of the previous line, and then doing the append.
Not sure about portability, but try:
${SED} '/-i lo/ a\
\
\
'"#Trusted Traffic\\
-A INPUT -s 10.153.156...
"
This technique works on BSD sed. You can maintain double quotes throughout with:
${SED} "/-i lo/ a\\
\\
\\
#Trusted Traffic\\
-A INPUT -s 10.153.156...
"
In either case, there must be no whitespace between the backslash and the end of the line.