Just started to learn GO. Need to add rule into iptables. Thats how i read ip from client
func get_client_ip(w http.ResponseWriter, r *http.Request) {
ip,_,_ := net.SplitHostPort(r.RemoteAddr)
}
I need use "ip" variable here
cmd := exec.Command("iptables", "-I INPUT -s ip -j ACCEPT")
What is the right way to use variables in os/exec ?
Command arguments map one to one with function arguments to exec.Command. Do it like this:
cmd := exec.Command("iptables", "-I", "INPUT", "-s", ip, "-j", "ACCEPT")
The code in the question passes "-I INPUT -s ip -j ACCEPT" as a single argument to the command. That's not what you want.