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

Does not work well on files with IPv4 and IPv6 addresses #2

Open
konfusator opened this issue Jan 21, 2015 · 0 comments
Open

Does not work well on files with IPv4 and IPv6 addresses #2

konfusator opened this issue Jan 21, 2015 · 0 comments

Comments

@konfusator
Copy link

On a dual stack machine a typical log file contains ipv4 and ipv6 addresses. Anonymizing with the algorithm "IPV4_NETWORK" will work as Ruby's IPAddr works with ipv4 and ipv6 adressess, but the result is not useful (with a key "24" 193.99.144.85 will become 193.99.144.0 (good) and 2a02:2e0:3fe:1001:7777:772e:2:85 will become 2a02:200:: (useless)).

A solution would be a new algorithm (called e.g. IP_NETWORK) using different prefix lengths for IPv4 and IPv6.

This could be done like

  def anonymize_ip_network(ip_string)
    # in JRuby 1.7.11 outputs as US-ASCII
    addr = IPAddr.new(ip_string)
    if addr.ipv4?
       addr.mask(@key.split(':')[0].to_i).to_s.force_encoding(Encoding::UTF_8)
    else
       addr.mask(@key.split(':')[1].to_i).to_s.force_encoding(Encoding::UTF_8)
    end
  end

expecting a key in the format "v4prefix:v6prefix" or

  def anonymize_ip_network(ip_string)
    # in JRuby 1.7.11 outputs as US-ASCII
    addr = IPAddr.new(ip_string)
    if addr.ipv4?
       addr.mask(@prefix_length[0]).to_s.force_encoding(Encoding::UTF_8)
    else
       addr.mask(@prefix_length[1]).to_s.force_encoding(Encoding::UTF_8)
    end
  end

with a new array parameter prefix_length.

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

No branches or pull requests

2 participants