Last active
June 23, 2018 13:14
-
-
Save pjperez/747f13b3e51ede649e489e792dff479d to your computer and use it in GitHub Desktop.
UDP hole puncher PoC
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 ( | |
"fmt" | |
"net" | |
"strconv" | |
"time" | |
) | |
//ServerIP defines the IP and port of the other peer | |
const ServerIP string = "1.2.3.4:10001" | |
func main() { | |
ServerAddr, err := net.ResolveUDPAddr("udp", ServerIP) | |
if err != nil { | |
fmt.Println(err) | |
} | |
LocalAddr, err := net.ResolveUDPAddr("udp", "0.0.0.0:10001") | |
if err != nil { | |
fmt.Println(err) | |
} | |
Conn, err := net.DialUDP("udp", LocalAddr, ServerAddr) | |
if err != nil { | |
fmt.Println(err) | |
} | |
defer Conn.Close() | |
i := 0 | |
var recvbuf [1024]byte | |
for { | |
// Send data | |
msg := strconv.Itoa(i) | |
i++ | |
sendbuf := []byte(msg) | |
_, err := Conn.Write(sendbuf) | |
if err != nil { | |
fmt.Println(err) | |
} | |
// Wait 1 second | |
time.Sleep(time.Second * 1) | |
// Receive data and print it on screen | |
rlen, _, err := Conn.ReadFromUDP(recvbuf[:]) | |
if err != nil { | |
fmt.Println(err) | |
} else { | |
fmt.Println(string(recvbuf[:rlen])) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment