- Luck Dragon: Asszociációs játék. :)
- sziku69: Fűzzük össze a szavakat :)
- MasterDeeJay: Alacsony fogyasztású házi szerver a korábbi projektekből összeépítve
- Argos: Adjátok vissza a netet! - szeretnék elaludni!
- D1Rect: Nagy "hülyétkapokazapróktól" topik
- sziku69: Szólánc.
- hcl: Döglött tabletből wifis kijelző kókány
- Geri Bátyó: Megint tahó voltam – SZEMÉLYISÉGFEJLŐDÉS
- Meggyi001: Nyilvános wc-k.....még mindig hiánypótló...
- gban: Ingyen kellene, de tegnapra
-
LOGOUT
Új hozzászólás Aktív témák
-
jerry311
nagyúr
válasz
jerry311 #14281 üzenetére
Problem solved.
Nyilván user error, meg a faszom abba aki elnevezgeti a Ruby gem-eket.Van egy gem, aminek a neve '
ip
', és egy másik, aminek a neve 'ruby-ip
'.
Csak hogy jó legyen, mindkettőt a 'require "ip"
' sorral lehet "meghívni".
Nyilván nem az volt telepítve, amelyikre a kódnak szüksége volt. Ezt javítva, működik ahogy kell. -
jerry311
nagyúr
hi,
Kis segítséget szeretnék, mert én lettem a kijelölt szopóroller tologató elvtárs.
Adott egy Ruby script, amit egy ex-kolléga írt ezer éve, és futott egy szerveren ősrégi Ruby-val. IT közölte, hogy új masinára kell költöztetni. Nyilván nem megy egyszerűen, tippelem voltak változások Rub oldalon, ami miatt nem megy a régi kód az új telepítésen. Ebben kérnék segítséget...
PlizA hiba:
Polling information from the NAT-R1 . . .
Traceback (most recent call last):
6: from /opt/scripts/snf.rb:35:in `<main>'
5: from /var/lib/gems/2.5.0/gems/snmp-1.3.2/lib/snmp/manager.rb:442:in `walk'
4: from /var/lib/gems/2.5.0/gems/snmp-1.3.2/lib/snmp/manager.rb:442:in `loop'
3: from /var/lib/gems/2.5.0/gems/snmp-1.3.2/lib/snmp/manager.rb:457:in `block in walk'
2: from /opt/scripts/snf.rb:59:in `block in <main>'
1: from /opt/scripts/snf.rb:59:in `new'
/opt/scripts/snf.rb:59:in `initialize': wrong number of arguments (given 1, expected 0) (ArgumentError)
A kód:
#=====================================================================
# ! To Whom it may concern !
# ------------------------------------
# I'm apologizing for this badly written script.
# I know it is alwfull and definatly not optimized, but given
# the 20 min that I had to write it in and the fact that
# it works perfectly I've not bother to spend more time on it.
#
# What it does?
# At the begining the script is asking for number of hosts,
# after which polls,via SNMP, ROUTER1 and ROUTER2 for all routes that
# are in their routing table. It filters all routes that start
# with 10.0 and calculate all free 10.0.x.x subnets which can
# fit the number of hosts specified in the begining
#
#======================================================================
require "ip"
require "snmp"
#starting variables
base_subnet = "10.0.0.0/17"
nat_r1_ip = "10.0.0.8"
nat_router_community = "snmpcommunity"
#preperation
routes = Array.new()
manager_r1 = SNMP::Manager.new(:host=> nat_r1_ip, :community => nat_router_community)
#manager_r2 = SNMP::Manager.new(:host=> nat_r2_ip, :community => nat_router_community)
#Get all routes starting with 10.0. from the NAT router
puts "Polling information from the ROUTER1 . . . "
manager_r1.walk(["1.3.6.1.2.1.4.24.4.1.1", "1.3.6.1.2.1.4.24.4.1.2"]) do |net, mask|
if /10\.0\./.match(net.value.to_s)
ip_string=""
case mask.value.to_s
when "255.255.255.255" then ip_string=net.value.to_s+"/"+"32"
when "255.255.255.254" then ip_string=net.value.to_s+"/"+"31"
when "255.255.255.252" then ip_string=net.value.to_s+"/"+"30"
when "255.255.255.248" then ip_string=net.value.to_s+"/"+"29"
when "255.255.255.240" then ip_string=net.value.to_s+"/"+"28"
when "255.255.255.224" then ip_string=net.value.to_s+"/"+"27"
when "255.255.255.192" then ip_string=net.value.to_s+"/"+"26"
when "255.255.255.128" then ip_string=net.value.to_s+"/"+"25"
when "255.255.255.0" then ip_string=net.value.to_s+"/"+"24"
when "255.255.254.0" then ip_string=net.value.to_s+"/"+"23"
when "255.255.252.0" then ip_string=net.value.to_s+"/"+"22"
when "255.255.248.0" then ip_string=net.value.to_s+"/"+"21"
when "255.255.240.0" then ip_string=net.value.to_s+"/"+"20"
when "255.255.224.0" then ip_string=net.value.to_s+"/"+"19"
when "255.255.192.0" then ip_string=net.value.to_s+"/"+"18"
when "255.255.128.0" then ip_string=net.value.to_s+"/"+"17"
when "255.255.0.0" then ip_string=net.value.to_s+"/"+"16"
else ip_string="0.0.0.0/0"
end
unless /10\.0\.0\./.match(net.value.to_s)
routes.push(IP.new(ip_string))
end
end
end
#Additional routes that should not be used aka EXEPTIONS
routes.push(IP.new("10.0.0.0/24"))
routes.push(IP.new("10.0.1.0/24"))
class NetworkHandler
def self.find_free_networks(base_subnet,used_subnets,hosts)
#initializing helper variables
free_networks = Array.new()
if hosts>2
possible_subnets = base_subnet.divide_by_hosts(hosts-2)
else
possible_subnets = base_subnet.divide_by_hosts(hosts)
end
#iterating
possible_subnets.each do |subnet|
not_matched=0
used_subnets.each do |used_subnet|
if subnet.is_in?(used_subnet)
break
else
if used_subnet.is_in?(subnet)
break
else
not_matched+=1
end
end
end
if not_matched == used_subnets.count
free_networks.push(subnet)
end
end
return free_networks
end
end
print "Specify the host count? "
hosts_count = gets.chomp
puts "Calculating the subnets . . . "
puts NetworkHandler.find_free_networks(IP.new(base_subnet),routes,hosts_count.to_i)
Új hozzászólás Aktív témák
Hirdetés
● olvasd el a téma összefoglalót!
- Luck Dragon: Asszociációs játék. :)
- Jól néz ki a világoskék iPhone 17 Air
- AMD Ryzen 9 / 7 / 5 / 3 5***(X) "Zen 3" (AM4)
- Kompakt vízhűtés
- Napelem
- Építő/felújító topik
- Formula-1
- Asztrofotózás
- Autós topik látogatók beszélgetős, offolós topikja
- Xiaomi 16: önfejlesztés önfotós oldalon
- További aktív témák...
- KBDFans Tofu 60 Redux, custom, angol feliratozású, PBT kupakos, hot swap, programozható billentyűzet
- Keychron Q0 Plus, kiterjesztett numpad kiosztású, halkított, PBT kupakos makropad billentyűzet
- Samsung Galaxy s24 Dual sim 8/128GB Független
- Keychron Q8 halkított, magyar feliratozású PBT kupakos billentyűzet + második csere belső
- Vegyes szimulátoros kiegészítők
- BESZÁMÍTÁS! ASUS H87I-PLUS H87 chipset alaplap garanciával hibátlan működéssel
- Telefon felvásárlás!! iPhone 13 Mini/iPhone 13/iPhone 13 Pro/iPhone 13 Pro Max/
- Bomba ár! Dell Latitude 5420 - i7-1185G7 I 16GB I 512SSD I HDMI I 14" FHD I Cam I W11 I Garancia!
- Lenovo M10 HD 32GB, Újszerű, 1 Év Garanciával
- DELL PowerEdge R630 rack szerver - 2xE5-2680v4 (28c/ 56t, 2.4/3.3GHz), 128GB RAM, 10G, áfás szla
Állásajánlatok
Cég: FOTC
Város: Budapest