Resolve Gitea Docker gateway without iproute2
All checks were successful
Candidate compatibility / prepare (push) Successful in 30s
Candidate compatibility / image ${{ matrix.id }} (push) Has been skipped
Candidate compatibility / fixture-contract (push) Successful in 1m9s
Candidate compatibility / lockstep clients Ruby 3.3 (push) Successful in 1m15s
Candidate compatibility / repository (push) Successful in 1m50s
Candidate compatibility / lockstep clients Ruby 3.4 (push) Successful in 1m49s
Candidate compatibility / Gitea full exact image matrix (push) Successful in 1m53s
Candidate compatibility / lockstep clients Ruby 4.0 (push) Successful in 2m16s
Candidate compatibility / lockstep clients Ruby 3.2 (push) Successful in 2m20s
All checks were successful
Candidate compatibility / prepare (push) Successful in 30s
Candidate compatibility / image ${{ matrix.id }} (push) Has been skipped
Candidate compatibility / fixture-contract (push) Successful in 1m9s
Candidate compatibility / lockstep clients Ruby 3.3 (push) Successful in 1m15s
Candidate compatibility / repository (push) Successful in 1m50s
Candidate compatibility / lockstep clients Ruby 3.4 (push) Successful in 1m49s
Candidate compatibility / Gitea full exact image matrix (push) Successful in 1m53s
Candidate compatibility / lockstep clients Ruby 4.0 (push) Successful in 2m16s
Candidate compatibility / lockstep clients Ruby 3.2 (push) Successful in 2m20s
This commit is contained in:
28
scripts/private_default_gateway.rb
Executable file
28
scripts/private_default_gateway.rb
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "ipaddr"
|
||||
|
||||
route_path = ARGV.fetch(0, "/proc/net/route")
|
||||
routes = File.foreach(route_path).drop(1).filter_map do |line|
|
||||
fields = line.split
|
||||
next unless fields.length >= 8
|
||||
next unless fields.fetch(1) == "00000000"
|
||||
next unless (fields.fetch(3).to_i(16) & 0x2) == 0x2
|
||||
|
||||
fields
|
||||
end
|
||||
|
||||
routes.sort_by { |fields| fields.fetch(6).to_i }.each do |fields|
|
||||
gateway_hex = fields.fetch(2)
|
||||
next unless gateway_hex.match?(/\A[0-9A-Fa-f]{8}\z/)
|
||||
|
||||
gateway = gateway_hex.scan(/../).reverse.map { |octet| octet.to_i(16) }.join(".")
|
||||
address = IPAddr.new(gateway)
|
||||
next unless address.ipv4? && address.private?
|
||||
|
||||
puts address
|
||||
exit 0
|
||||
end
|
||||
|
||||
abort "no private IPv4 default-route gateway found in #{route_path}"
|
||||
Reference in New Issue
Block a user