updated dip

This commit is contained in:
Paul 2020-01-21 18:42:34 +01:00
parent f77f3f95a9
commit f595597fc0
5 changed files with 14 additions and 17 deletions

View File

@ -2,12 +2,12 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"net" "net"
"net/http" "net/http"
"os" "os"
"strings" "strings"
"log"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/likexian/whois-go" "github.com/likexian/whois-go"
@ -24,12 +24,12 @@ func (ip *IP) GetIPInfo(c echo.Context) (err error) {
err = ip.CheckIPAddress() err = ip.CheckIPAddress()
if err != nil { if err != nil {
return err return err
} }
err = ip.GetHostname() err = ip.GetHostname()
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
return return
@ -39,10 +39,7 @@ func (ip *IP) GetIPInfo(c echo.Context) (err error) {
func Dip(c echo.Context) (err error) { func Dip(c echo.Context) (err error) {
var ip IP var ip IP
err = ip.GetIPInfo(c) ip.GetIPInfo(c)
if err != nil {
return c.Render(http.StatusInternalServerError, "error.html", err)
}
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) { if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
return c.Render(http.StatusOK, "index.html", ip) return c.Render(http.StatusOK, "index.html", ip)
@ -70,7 +67,7 @@ func (ip *IP) CheckIPAddress() (err error) {
func (ip *IP) GetHostname() (err error) { func (ip *IP) GetHostname() (err error) {
revip, err := net.LookupAddr(ip.IP) revip, err := net.LookupAddr(ip.IP)
if err != nil { if err != nil {
return fmt.Errorf(fmt.Sprintf("Supplied address \"%s\" doesn't have a valid reverse DNS entry", ip.IP)) return err
} }
ip.Hostname = revip[0] ip.Hostname = revip[0]
return return

View File

View File

@ -1,9 +1,9 @@
<html> <html>
<head> <head>
<title>Public IP Address</title> {{ template "head.html" .}}
</head> </head>
<body> <body>
<h1>Error</h1> <h1>Error</h1>
<p>{{ . }} isn't a IP address</p> <p>{{ . }}</p>
</body> </body>
</html> </html>

View File

@ -1,5 +1,6 @@
<meta charset="utf-8"> <title>Public IP Address</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta charset="utf-8">
<link rel="stylesheet" href="css/uikit.min.css" /> <meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/uikit.min.js"></script> <link rel="stylesheet" href="css/uikit.min.css" />
<script src="js/uikit-icons.min.js"></script> <script src="js/uikit.min.js"></script>
<script src="js/uikit-icons.min.js"></script>

View File

@ -1,6 +1,5 @@
<html> <html>
<head> <head>
<title>Public IP Address</title>
{{ template "head.html" .}} {{ template "head.html" .}}
</head> </head>
<body> <body>