<commit_before>module ArpScan
  require 'open3'

  IP_ADDRESS_REGEX = /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/

  MAC_ADDRESS_REGEX = /([0-9A-F]{2}[:]){5}([0-9A-F]{2})/i

  def self.fetch(ip_address, interface, options={})
    raise 'Must run as root' unless Process.uid == 0
    raise 'invalid IP address' unless ip_address =~ IP_ADDRESS_REGEX
    cmd = "arp-scan -l -s #{ip_address} -I #{interface} -q"
    addresses = []
    Open3.popen3(cmd) do |stdin, stdout, sterr, wait_thr|
      stdout.each_line do |line|
        addresses << extract_mac_address(line)
      end
    end
    addresses.delete_if{|a| a.nil?}.uniq!
    puts addresses if options[:verbose]
    addresses
  end

  def self.extract_mac_address(str)
    str.match(MAC_ADDRESS_REGEX) { |m| m }
  end
end<commit_msg>protect if arp-scan not installed<commit_after>module ArpScan
  require 'open3'

  IP_ADDRESS_REGEX = /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/

  MAC_ADDRESS_REGEX = /([0-9A-F]{2}[:]){5}([0-9A-F]{2})/i

  def self.fetch(ip_address, interface, options={})
    raise 'Must run as root' unless Process.uid == 0
    raise 'arp-scan not installed' unless arp_scan_installed?
    raise 'invalid IP address' unless ip_address =~ IP_ADDRESS_REGEX
    cmd = "arp-scan -l -s #{ip_address} -I #{interface} -q"
    addresses = []
    Open3.popen3(cmd) do |stdin, stdout, sterr, wait_thr|
      stdout.each_line do |line|
        addresses << extract_mac_address(line)
      end
    end
    addresses.delete_if{|a| a.nil?}.uniq!
    puts addresses if options[:verbose]
    addresses
  end

  def self.extract_mac_address(str)
    str.match(MAC_ADDRESS_REGEX) { |m| m }
  end

  def self.arp_scan_installed?
    `which arp-scan`
    $?.success?
  end
end
{'fraction_non_alphanumeric': 0.1633122484186314, 'fraction_numerical': 0.02185163887291547, 'mean_word_length': 3.254278728606357, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1022954', 'n_tokens_mistral': 689, 'n_tokens_neox': 676, 'n_words': 143}