Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't work with IPv6 #11

Open
ruben-herold opened this issue May 8, 2023 · 0 comments
Open

Can't work with IPv6 #11

ruben-herold opened this issue May 8, 2023 · 0 comments

Comments

@ruben-herold
Copy link

hi,

your code is not IPv6 save:

        if($GelfServer -notmatch "^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$")
        {
            $GelfServer = [String]$([System.Net.Dns]::GetHostAddressesAsync($GelfServer)).Result[0]  
        }

        # Create a UDP client to be used to send data
        $Address = [system.net.IPAddress]::Parse($GelfServer) 
        $EndPoint = New-Object System.Net.IPEndPoint($Address, $Port)
        $UdpClient = new-Object System.Net.Sockets.UdpClient        
        ....
        $UDPclient.SendAsync($CompressedJSON, $CompressedJSON.Length,$EndPoint) | Out-Null
  1. The regex did not match IPv6 addresses
  2. New-Object System.Net.IPEndPoint($Address, $Port) need the right address family

Why not use [system.net.IPAddress]::Parse($GelfServer) instead of the regex?
Then check if Address is IPv4 or IPv6 and set the right address family?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant