add external ip route command
This commit is contained in:
parent
1c02c700fa
commit
24406ca0f4
|
@ -1,3 +1,4 @@
|
|||
test.sh
|
||||
openvpn-dm-mgt-server
|
||||
openvpn-dm-mgt-server.conf
|
||||
iproute/iproute
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func checkArg(args []string, pos int, value string) {
|
||||
if args[pos] != value {
|
||||
fmt.Println(errors.New("invalid command : " + args[pos]))
|
||||
os.Exit(10 + pos)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 6 {
|
||||
fmt.Println(errors.New("missing args"), len(os.Args))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
args := os.Args[1:]
|
||||
|
||||
r := regexp.MustCompile("[^a-zA-Z0-9.-]")
|
||||
var ip string
|
||||
|
||||
checkArg(args, 0, "route")
|
||||
checkArg(args, 1, "replace")
|
||||
|
||||
if testip := net.ParseIP(args[2]); testip != nil {
|
||||
ip = testip.String()
|
||||
} else {
|
||||
fmt.Println(errors.New("invalid ip"))
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
checkArg(args, 3, "dev")
|
||||
|
||||
dev := r.ReplaceAllString(args[4], "")
|
||||
|
||||
cmd := exec.Command("/bin/ip", "route", "replace", ip, "dev", dev)
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(3)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue