mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 07:58:51 +01:00
ApplyGateWay bug fix
This commit is contained in:
parent
6c0bbb1101
commit
6ccb04ce06
@ -271,15 +271,16 @@ func (self *GateWayPage) ApplyGateWay( gateway string ) bool {
|
||||
out := UI.System("sudo ifconfig usb0 | grep inet | tr -s \" \"| cut -d \" \" -f3")
|
||||
if len(out) > 7 {
|
||||
if strings.Contains(out,"error") == false {
|
||||
out = strings.Trim(out,"\r\n ")
|
||||
parts := strings.Split(out,".")
|
||||
if len(parts) == 4 { // IPv4
|
||||
tmp,err := strconv.Atoi(parts[3])
|
||||
if err == nil {
|
||||
tmp = tmp +1
|
||||
if tmp > 255 {
|
||||
tmp = 255
|
||||
if tmp == 0 {
|
||||
tmp = tmp +1
|
||||
}else if tmp > 0 {
|
||||
tmp = tmp -1
|
||||
}
|
||||
|
||||
parts[3] = strconv.Itoa(tmp)
|
||||
ipaddress := strings.Join(parts,".")
|
||||
UI.System( fmt.Sprintf("sudo route add default gw %s",ipaddress) )
|
||||
|
||||
@ -259,3 +259,19 @@ func System(cmd string) string {
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func SystemTrim(cmd string) string {
|
||||
ret := ""
|
||||
out,err := exec.Command("bash","-c",cmd).Output()
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
//exit code !=0 ,but it can be ignored
|
||||
}else{
|
||||
fmt.Println(err)
|
||||
}
|
||||
}else {
|
||||
ret = string(out)
|
||||
}
|
||||
|
||||
return strings.Trim(ret,"\r\n")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user