-1

Here is my python script for calling IPtables and I need SQLite output to make a rule (df2)

subprocess.run(["/usr/sbin/iptables", "-A", "INPUT", "-p", "udp", "-m", "udp", "--dport 5060", "-m" "string", "--string" , "/home/as/Documents/mydf.csv", "-algo", "bm", "--to 655535", "-j" ,"REJECT"]) 

Error I am getting

iptables v 1.8.4v(legacy): unknown option --string 
9
  • "-algo bm" needs to be two strings: "-algo", "bm". Same with "--to 65535". The path to iptables is wrong, so this can't be your exact code. Commented Feb 26, 2021 at 0:36
  • ...and "--dport 5060" Commented Feb 26, 2021 at 2:05
  • @TimRoberts I also tried separating all the strings, but no luck, also could you please let me know how to write path location, I am writing path as subprocess.call(["/usr/sbin/iptables"(iptable file location),..(all the middle strings separated by " ")....,"/home/Documents/.csv(file location)"]) Commented Feb 26, 2021 at 5:51
  • @larsks I tried separating all the string Commented Feb 26, 2021 at 5:53
  • What I meant was that, in the example in your question, you have "usr/bin/iptables" without the leading slash. You do have the iptables-string extension installed? And why are you using a Windows file path in a Linux system? Commented Feb 26, 2021 at 6:04

1 Answer 1

0

In the code you posted in your answer, you have usr/sbin/iptables without a leading slash. You should use /usr/sbin/iptables.

You also have several parts in your call to subprocess.run() where you needed to separate the arguments into separate list items. You also forgot a comma between "-m" and "string".

Try this:

subprocess.run([ "/usr/sbin/iptables", "-A", "INPUT", "-p", "udp", "-m", "udp", "--dport", "5060", "-m", "string", "--string", "insert csv file location here", "-algo", "bm", "--to", "655535", "-j", "REJECT", ]) 
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, still getting the same error iptables v 1.8.4v(legacy): no command specified
Then the problem is likely with your iptables command, not with your python code.
Hi, another error iptables v 1.8.4v(legacy): unknown option "--string"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.