|
@@ -0,0 +1,40 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "net"
|
|
|
+ "os"
|
|
|
+ "strconv"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ if len(os.Args) != 3 {
|
|
|
+ fmt.Println("usage: %s ip-address\n", os.Args[0])
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ port, _ := strconv.Atoi(os.Args[2])
|
|
|
+ OpenRequestIPV4(os.Args[1], port)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// OpenRequestIPV4 Opens a request to an ipv4 tcp network address
|
|
|
+func OpenRequestIPV4(ipv4Address string, port int) {
|
|
|
+
|
|
|
+ service := ipv4Address + ":" + strconv.Itoa(port)
|
|
|
+ tcpv4Addr, _ := net.ResolveTCPAddr("tcp", service)
|
|
|
+ conn, _ := net.DialTCP("tcp4", nil, tcpv4Addr)
|
|
|
+ _, _ = conn.Write([]byte("HEAD / HTTP/1.0\r\n\r\nGet index.html"))
|
|
|
+
|
|
|
+ result, _ := ioutil.ReadAll(conn)
|
|
|
+
|
|
|
+ fmt.Println(string(result))
|
|
|
+
|
|
|
+ os.Exit(0)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func checkError(err error) {
|
|
|
+ fmt.Println(err.Error())
|
|
|
+}
|