Fixed internet connection errors. All right but still cannot establish connection.

This commit is contained in:
Andrey Egorov 2024-07-29 15:17:00 +03:00
parent 225a0d2264
commit e0110c558e
2 changed files with 16 additions and 8 deletions

View File

@ -5,6 +5,7 @@ COPY ./ ./
RUN go mod download
RUN apt-get update
RUN apt-get install -y iputils-ping
RUN apt-get install -y ppp
RUN apt-get install -y net-tools

View File

@ -12,7 +12,7 @@ import (
)
var apns = map[string]string{
"tinkoff": "m.tinkoff",
"Tinkoff": "m.tinkoff",
}
const pppConfigName = "annalistnet"
@ -132,7 +132,7 @@ func (c *conn) ConfigurePPP() error {
config := fmt.Sprintf(pppConfig, apn, c.port.GetName(), c.port.GetBaudrate())
// Write to file
f, err := os.OpenFile("etc/ppp/pears/"+pppConfigName, os.O_CREATE, 0666)
f, err := os.OpenFile("/etc/ppp/peers/"+pppConfigName, os.O_CREATE | os.O_WRONLY, 0666)
if err != nil {
return fmt.Errorf("open ppp config file %w", err)
}
@ -175,7 +175,7 @@ func (c *conn) connect() error {
if err != nil {
return fmt.Errorf("execute connect cmd: %w", err)
}
c.logger.Println("DEBUG pon response:", resp)
c.logger.Println("DEBUG pon response:", string(resp))
return nil
}
@ -184,7 +184,7 @@ func (c *conn) diconnect() error {
if err != nil {
return fmt.Errorf("execute disconnect cmd: %w", err)
}
c.logger.Println("DEBUG poff response:", resp)
c.logger.Println("DEBUG poff response:", string(resp))
return nil
}
@ -205,7 +205,7 @@ func (c *conn) Init() error {
if err != nil {
return fmt.Errorf("execute ifconfig cmd: %w", err)
}
c.logger.Println("DEBUG ifconfig resp:", resp)
c.logger.Println("DEBUG ifconfig resp:", string(resp))
// Test connectin using Ping
c.logger.Println("Test...")
@ -218,11 +218,18 @@ func (c *conn) Init() error {
func (c *conn) Ping() bool {
// Test - try to connect to Google DNS
// ping -I ppp0 8.8.8.8
resp, err := exec.Command("ping", "-I", "ppp0", "8.8.8.8").Output()
resp, err := exec.Command("ping", "8.8.8.8").Output()
if err != nil {
c.logger.Println("Ping cmd error:", err)
c.logger.Println("Ping 1 cmd error:", err)
}
c.logger.Println("Ping resp:", resp)
c.logger.Println("Ping 1 resp:", string(resp))
resp, err = exec.Command("ping", "-I", "ppp0", "8.8.8.8").Output()
if err != nil {
c.logger.Println("Ping 2 cmd error:", err)
}
c.logger.Println("Ping 2 resp:", string(resp))
return !strings.Contains(string(resp), "Destination Host Unreachable") // tmp solution
}