-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip.go
43 lines (37 loc) · 726 Bytes
/
ip.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
package main
import (
"fmt"
"net/http"
"strings"
"github.com/parnurzeal/gorequest"
"github.com/urfave/cli"
)
func init() {
commands = append(commands,
cli.Command{
Name: "myip",
Usage: "show my ip address",
ArgsUsage:" ",
Action: myip,
},
// cli.Command{
// Name: "ipaddr",
// Usage: "show address of ip",
// Action: ipaddr,
// },
)
}
func myip(ctx *cli.Context) {
resp, body, err := gorequest.New().Get("http://myip.ipip.net").End()
if err != nil {
fmt.Println(err)
} else {
if resp.StatusCode != http.StatusOK {
fmt.Printf("%d - %s\n", resp.StatusCode, resp.Status)
} else {
fmt.Println(strings.TrimSpace(body))
}
}
}
// func ipaddr(ctx *cli.Context) {
// }