Skip to content

Instantly share code, notes, and snippets.

@vibhavp
Created August 28, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vibhavp/179782eb5b2c338ba25532b10a40ffc5 to your computer and use it in GitHub Desktop.
Save vibhavp/179782eb5b2c338ba25532b10a40ffc5 to your computer and use it in GitHub Desktop.
Useage: ./ip http://<domain>/<endpoint>
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