Skip to content

Can't work with IPv6 #11

Description

@ruben-herold

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions