-
Notifications
You must be signed in to change notification settings - Fork 3
/
deviceinfo.go
64 lines (55 loc) · 1.38 KB
/
deviceinfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @Author Rafal Golarz
* http://rafalgolarz.com/blog/2017/01/15/running_golang_on_android/
*/
package main
import (
"encoding/json"
"fmt"
"log"
"os/exec"
)
/*
* Termux API: termux-telephony-deviceinfo
*/
var Deviceinfo struct {
Data_activity string
Data_state string
Device_id string
Device_software_version string
Phone_count int
Phone_type string
Network_operator string
Network_operator_name string
Network_country_iso string
Network_type string
Network_roaming bool
Sim_country_iso string
Sim_operator string
Sim_operator_name string
Sim_serial_number string
Sim_state string
}
func main() {
cmd := exec.Command("termux-telephony-deviceinfo")
//StdoutPipe returns a pipe that will be connected to
//the command's standard output when the command starts
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
if err := json.NewDecoder(stdout).Decode(&Deviceinfo); err != nil {
log.Fatal(err)
}
//Wait waits for the command to exit
//It must have been started by Start
if err := cmd.Wait(); err != nil {
log.Fatal(err)
}
fmt.Printf("Your network type: %s, network operator name: %s\n",
Deviceinfo.Network_type,
Deviceinfo.Network_operator_name)
}