Created
August 28, 2020 10:56
-
-
Save vibhavp/179782eb5b2c338ba25532b10a40ffc5 to your computer and use it in GitHub Desktop.
Useage: ./ip http://<domain>/<endpoint>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/binary" | |
"fmt" | |
"log" | |
"net" | |
"net/url" | |
"os" | |
"strconv" | |
) | |
func main() { | |
u, err := url.Parse(os.Args[1]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
ip, err := net.ResolveIPAddr("ip4", u.Host) | |
if err != nil { | |
log.Fatal(err) | |
} | |
ip4 := ip.IP.To4() | |
u.Host = strconv.FormatInt(int64(binary.BigEndian.Uint32([]byte{ip4[0], ip4[1], ip4[2], ip4[3]})), 10) | |
fmt.Println(u.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment