How to use ip method of Platform Package

Best Selenium code snippet using Platform.ip

helpers_spec.rb

Source:helpers_spec.rb Github

copy

Full Screen

...5 end6 subject { DummyClass.new }7 describe '#get_sysconfig_path' do8 before do9 allow(subject).to receive(:[]).with('ip_version').and_return(ip_version)10 end11 context 'When given an ipv4' do12 let(:ip_version) { :ipv4 }13 it 'returns the correct path' do14 expect(subject.get_sysconfig_path(ip_version)).to match('/etc/sysconfig/iptables-config')15 end16 end17 context 'When given an ipv6' do18 let(:ip_version) { :ipv6 }19 it 'returns the correct path' do20 expect(subject.get_sysconfig_path(ip_version)).to match('/etc/sysconfig/ip6tables-config')21 end22 end23 end24 describe '#get_sysconfig' do25 before do26 allow(subject).to receive(:[]).with('ip_version').and_return(ip_version)27 end28 context 'When given an ipv4' do29 let(:ip_version) { :ipv4 }30 it 'returns the correct path' do31 expect(subject.get_sysconfig(ip_version)).to match(32 'IPTABLES_MODULES' => '',33 'IPTABLES_MODULES_UNLOAD' => 'no',34 'IPTABLES_SAVE_ON_STOP' => 'no',35 'IPTABLES_SAVE_ON_RESTART' => 'no',36 'IPTABLES_SAVE_COUNTER' => 'no',37 'IPTABLES_STATUS_NUMERIC' => 'yes',38 'IPTABLES_STATUS_VERBOSE' => 'no',39 'IPTABLES_STATUS_LINENUMBERS' => 'yes'40 )41 end42 end43 context 'When given an ipv6' do44 let(:ip_version) { :ipv6 }45 it 'returns the correct path' do46 expect(subject.get_sysconfig(ip_version)).to match(47 'IP6TABLES_MODULES' => '',48 'IP6TABLES_MODULES_UNLOAD' => 'no',49 'IP6TABLES_SAVE_ON_STOP' => 'no',50 'IP6TABLES_SAVE_ON_RESTART' => 'no',51 'IP6TABLES_SAVE_COUNTER' => 'no',52 'IP6TABLES_STATUS_NUMERIC' => 'yes',53 'IP6TABLES_STATUS_VERBOSE' => 'no',54 'IP6TABLES_STATUS_LINENUMBERS' => 'yes'55 )56 end57 end58 end59 # describe '#package_names' do60 # before do61 # allow(subject).to receive(:[]).with('platform_family').with('platform_version').and_return(platform_family).and_return(platform_version)62 # end63 # context 'When platform family is debian' do64 # let(:platform_family) { 'debian' }65 # let(:platform_version) { 10 }66 # it 'returns the correct packages' do67 # expect(subject.package_names()).to match(%w(iptables iptables-persistent))68 # end69 # end70 # context 'When platform family is centos 6' do71 # let(:platform_family) { 'centos' }72 # let(:platform_version) { 6 }73 # it 'returns the correct packages' do74 # expect(subject.package_names()).to match(%w(iptables))75 # end76 # end77 # %w(rhel fedora amazon).each do |platform|78 # context "When platform family is #{platform}" do79 # let(:platform_family) { platform }80 # let(:platform_version) { 7 }81 # it 'returns the correct packages' do82 # expect(subject.package_names()).to match(%w(iptables iptables-services iptables-utils))83 # end84 # end85 # end86 # end87 describe '#default_iptables_rules_file' do88 before do89 allow(subject).to receive(:[]).with('ip_version').with('platform_family').and_return(ip_version).and_return(platform_family)90 end91 context 'When given an ipv4 on rhel' do92 let(:ip_version) { :ipv4 }93 let(:platform_family) { 'rhel' }94 it 'returns the correct path' do95 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/sysconfig/iptables')96 end97 end98 context 'When given an ipv6 on rhel' do99 let(:ip_version) { :ipv6 }100 let(:platform_family) { 'rhel' }101 it 'returns the correct path' do102 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/sysconfig/ip6tables')103 end104 end105 context 'When given an ipv4 on amazon' do106 let(:ip_version) { :ipv4 }107 let(:platform_family) { 'amazon' }108 it 'returns the correct path' do109 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/sysconfig/iptables')110 end111 end112 context 'When given an ipv6 on amazon' do113 let(:ip_version) { :ipv6 }114 let(:platform_family) { 'amazon' }115 it 'returns the correct path' do116 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/sysconfig/ip6tables')117 end118 end119 context 'When given an ipv4 on fedora' do120 let(:ip_version) { :ipv4 }121 let(:platform_family) { 'fedora' }122 it 'returns the correct path' do123 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/sysconfig/iptables')124 end125 end126 context 'When given an ipv6 on fedora' do127 let(:ip_version) { :ipv6 }128 let(:platform_family) { 'fedora' }129 it 'returns the correct path' do130 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/sysconfig/ip6tables')131 end132 end133 context 'When given an ipv4 on debian' do134 let(:ip_version) { :ipv4 }135 let(:platform_family) { 'debian' }136 it 'returns the correct path' do137 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/iptables/rules.v4')138 end139 end140 context 'When given an ipv6 on debian' do141 let(:ip_version) { :ipv6 }142 let(:platform_family) { 'debian' }143 it 'returns the correct path' do144 expect(subject.default_iptables_rules_file(ip_version)).to match('/etc/iptables/rules.v6')145 end146 end147 end148 describe '#get_default_chains_for_table' do149 before do150 allow(subject).to receive(:[]).with('table_name').and_return(table_name)151 end152 context 'When given an unknown table' do153 let(:table_name) { :does_not_exist }154 it 'returns an empty Hash' do155 expect(subject.get_default_chains_for_table(table_name)).to eq({})156 end157 end158 context 'When given the table filter' do...

Full Screen

Full Screen

ipparse.rb

Source:ipparse.rb Github

copy

Full Screen

...14# limitations under the License.15#16# Initial developer(s): Jeff Mace17class IPParse18 IPV4 = :ipv419 IPV6 = :ipv620 21 def initialize22 @klass = get_platform_klass().new()23 @parsed = nil24 end25 26 # Return a nested array of the parsed interface information27 # { 28 # "eth0" => {29 # :ipv4 => { :address => "1.2.3.4", :netmask => "255.255.255.0" },30 # :ipv6 => { :address => "fe80::a00:27ff:fe1f:84a5", :netmask => "64" }31 # }32 # }33 def get_interfaces34 parse()35 return @parsed36 end37 38 def get_interface_address(interface, type = IPV4)39 parse()40 41 unless @parsed.has_key?(interface)42 return nil43 end44 45 unless @parsed[interface].has_key?(type)46 return nil47 end48 49 return @parsed[interface][type]50 end51 52 private53 54 def get_platform55 RUBY_PLATFORM56 end57 58 # Have the platform class parse the IP configuration information 59 # it just collected. If the information has already been parsed60 # the steps can be skipped.61 def parse62 if @parsed != nil63 return64 end65 66 @parsed = @klass.parse(get_raw_ip_configuration())67 end68 69 # Have the platform class to collect IP configuration information70 def get_raw_ip_configuration71 @klass.get_raw_ip_configuration()72 end73 74 # Iterate through all of the platform classes until one declares 75 # it is able to support the current system.76 def get_platform_klass(platform = nil)77 if platform == nil78 platform = get_platform()79 end80 81 platform = platform.downcase()82 83 IPParsePlatform.subclasses().each{84 |klass|85 begin86 supports_platform = klass.supports_platform?(platform)87 if supports_platform == true88 return klass89 end90 rescue NoMethodError91 # Eat this error because the platform didn't define the required method92 end93 }94 95 throw Exception.new("Unable to support the #{platform} platform")96 end97end98class IPParsePlatform99 def initialize100 @interfaces = {}101 end102 103 def add_ipv4(name, address, netmask)104 unless @interfaces.has_key?(name)105 @interfaces[name] = {}106 end107 108 @interfaces[name][IPParse::IPV4] = {109 :address => address,110 :netmask => netmask111 }112 end113 114 def add_ipv6(name, address, netmask)115 unless @interfaces.has_key?(name)116 @interfaces[name] = {}117 end118 119 @interfaces[name][IPParse::IPV6] = {120 :address => address,121 :netmask => netmask122 }123 end124 125 def get_raw_ip_configuration126 throw Exception.new("Undefined method #{self.class.name}:get_raw_ip_configuration")127 end128 129 def self.inherited(subclass)130 @subclasses ||= []131 @subclasses << subclass132 end133 134 def self.subclasses135 @subclasses136 end137end138# Load all platform classes so they can be registered139Dir.glob("#{File.dirname(__FILE__)}/ipparse/platforms/*.rb").each{|platform|140 require platform141}...

Full Screen

Full Screen

logstash_util.rb

Source:logstash_util.rb Github

copy

Full Screen

1# Encoding: utf-82module Logstash3 def self.service_ip(node, instance = 'default', service = 'elasticsearch', interface = nil)4 if Chef::Config[:solo]5 service_ip = get_attribute_or_default(node, instance, "#{service}_ip")6 else7 results = []8 service_query = get_attribute_or_default(node, instance, "#{service}_query")9 Chef::Search::Query.new.search(:node, service_query) { |o| results << o }10 if !results.empty?11 service_ip = get_ip_for_node(results[0], interface)12 else13 service_ip = get_attribute_or_default(node, instance, "#{service}_ip")14 end15 end16 end17 def self.get_ip_for_node(node, interface)18 if interface.nil?19 service_ip = node['ipaddress']20 else21 service_ip = node['network']['interfaces'][interface]['addresses'].to_hash.find do |_, addr_info|22 addr_info['family'] == 'inet'23 end.first24 end25 end26 def self.get_attribute_or_default(node, instance_name, attribute_name)27 instance_attr = {} unless node['logstash']['instance'][instance_name]28 instance_attr = deep_fetch(node, 'logstash', 'instance', instance_name, attribute_name)29 default_attr = deep_fetch(node, 'logstash', 'instance_default', attribute_name)30 instance_attr || default_attr31 end32 def self.determine_native_init(node)33 platform_major_version = determine_platform_major_version(node)34 case node['platform']35 when 'ubuntu'36 if platform_major_version >= 6.1037 'upstart'38 else39 'sysvinit'40 end41 when 'debian'42 'sysvinit'43 when 'redhat', 'centos', 'scientific'44 if platform_major_version <= 645 'sysvinit'46 else47 'systemd'48 end49 when 'amazon'50 if platform_major_version < 2011.0251 'sysvinit'52 else53 'upstart'54 end55 when 'fedora'56 if platform_major_version < 1557 'sysvinit'58 else59 'systemd'60 end61 else62 Chef::Log.fatal("We cannot determine your distribution's native init system")63 end64 end65 def self.upstart_supports_user?(node)66 platform_major_version = determine_platform_major_version(node)67 case node['platform']68 when 'ubuntu'69 if platform_major_version < 12.0470 false71 else72 true73 end74 when 'redhat', 'centos', 'scientific', 'amazon'75 false76 else77 Chef::Log.fatal("#{node['platform']} does not use upstart")78 end79 end80 def self.determine_platform_major_version(node)81 if node['platform'] == 'ubuntu' || node['platform'] == 'amazon'82 node['platform_version'].to_f83 else84 node['platform_version'].split('.').first.to_i85 end86 end87 private88 # Adapted from @sathvargo's chef-sugar project, as there's no way to install89 # a gem via libraries, and we didn't want to much up the recipes too much yet:90 # https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/node.rb91 def self.deep_fetch(node, *keys)92 keys.map!(&:to_s)93 keys.reduce(node.attributes.to_hash) do |hash, key|94 hash[key]95 end96 rescue NoMethodError97 nil98 end99end...

Full Screen

Full Screen

ping_sweep.rb

Source:ping_sweep.rb Github

copy

Full Screen

...14 include Msf::Post::Common15 def initialize(info={})16 super( update_info( info,17 'Name' => 'Multi Gather Ping Sweep',18 'Description' => %q{ Performs IPv4 ping sweep using the OS included ping command.},19 'License' => MSF_LICENSE,20 'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],21 'Version' => '$Revision: 15960 $',22 'Platform' => [ 'windows','linux', 'osx', 'bsd', 'solaris' ],23 'SessionTypes' => [ 'meterpreter', 'shell' ]24 ))25 register_options(26 [27 OptAddressRange.new('RHOSTS', [true, 'IP Range to perform ping sweep against.']),28 ], self.class)29 end30 # Run Method for when run command is issued31 def run32 iprange = datastore['RHOSTS']33 print_status("Performing ping sweep for IP range #{iprange}")34 iplst = []35 begin36 ipadd = Rex::Socket::RangeWalker.new(iprange)37 numip = ipadd.num_ips38 while (iplst.length < numip)39 ipa = ipadd.next_ip40 if (not ipa)41 break42 end43 iplst << ipa44 end45 if session.type =~ /shell/46 # Only one thread possible when shell47 thread_num = 148 # Use the shell platform for selecting the command49 platform = session.platform50 else51 # When in Meterpreter the safest thread number is 1052 thread_num = 1053 # For Meterpreter use the sysinfo OS since java Meterpreter returns java as platform54 platform = session.sys.config.sysinfo['OS']55 end56 platform = session.platform57 case platform58 when /win/i59 count = " -n 1 "60 cmd = "ping"61 when /solaris/i62 cmd = "/usr/sbin/ping"63 else64 count = " -n -c 1 -W 2 "65 cmd = "ping"66 end67 ip_found = []68 while(not iplst.nil? and not iplst.empty?)69 a = []70 1.upto(thread_num) do71 a << framework.threads.spawn("Module(#{self.refname})", false, iplst.shift) do |ip_add|72 next if ip_add.nil?73 if platform =~ /solaris/i74 r = cmd_exec(cmd, "-n #{ip_add} 1")75 else76 r = cmd_exec(cmd, count + ip_add)77 end78 if r =~ /(TTL|Alive)/i79 print_status "\t#{ip_add} host found"80 ip_found << ip_add81 else82 vprint_status("\t#{ip_add} host not found")83 end84 end85 end86 a.map {|x| x.join }87 end88 rescue Rex::TimeoutError, Rex::Post::Meterpreter::RequestError89 rescue ::Exception => e90 print_status("The following Error was encountered: #{e.class} #{e}")91 end92 ip_found.each do |ip|93 report_host(:host => ip)94 end95 end96end...

Full Screen

Full Screen

ip_tests.rb

Source:ip_tests.rb Github

copy

Full Screen

1Shindo.tests('Fog::Compute[:glesys] | ip requests', ['glesys']) do2 @free_ip = nil3 @ips = nil4 tests('success') do5 tests("#ip_list_own()").formats(Glesys::Compute::Formats::Ips::IPLIST) do6 pending if Fog.mocking?7 Fog::Compute[:glesys].ip_list_own.body['response']8 end9 tests("#ip_list_free(:datacenter => 'Falkenberg, :platform => 'Xen', :ipversion => 4)"10 ).formats(Glesys::Compute::Formats::Ips::IPLIST_ALL) do11 pending if Fog.mocking?12 ips = Fog::Compute[:glesys].ip_list_free(13 :datacenter => "Falkenberg",14 :platform => "Xen",15 :ipversion => 416 )17 @free_ip = ips.body['response']['iplist']['ipaddresses'].first18 ips.body['response']19 end20 tests("#ip_take(:datacenter => 'Falkenberg', :platform => 'Xen', :ipversion => 4, :ipaddress => #{@free_ip})"21 ).formats(Glesys::Compute::Formats::Ips::IPLIST_CATCH_RELEASE) do22 pending if Fog.mocking?23 Fog::Compute[:glesys].ip_take(24 :datacenter => "Falkenberg",25 :platform => "Xen",26 :ipversion => 4,27 :ipaddress => @free_ip28 ).body['response']29 end30 tests("#ip_release(:ipaddress => '#{@free_ip}', :ipversion => 4)"31 ).formats(Glesys::Compute::Formats::Ips::IPLIST_CATCH_RELEASE) do32 pending if Fog.mocking?33 Fog::Compute[:glesys].ip_release(34 :ipaddress => @free_ip,35 :ipversion => 436 ).body['response']37 end38 # ip_details()39 # ip_add()40 # ip_remove()41 end42 tests('failure') do43 tests("#ip_take_argument_error()").raises(Excon::Errors::HTTPStatusError) do44 pending if Fog.mocking?45 ip = Fog::Compute[:glesys].ips.new(46 :datacenter => "Falkenberg",47 :platform => "Xen",48 :version => 4,49 :ip => "127.0.0.1"50 )51 ip.take52 end53 end54end...

Full Screen

Full Screen

AppiumConnect.rb

Source:AppiumConnect.rb Github

copy

Full Screen

...5require_relative 'FileSystemHelpers'6require_relative 'Android'7require_relative 'Appium'8require_relative 'iOS.rb'9require_relative 'ip'10platform = get_platform()11if platform == :windows12 require 'Win32API'13end14def shortname long_name15 return '/c' + long_name[2..-1] if long_name[0..1] == 'C:'16 long_name17end18input_array = ARGV19ip = ENV['IP'] || Ip.host_ip20host_port = ip.include?(':') ? ip.split(':')[-1] : nil21ip = ip.include?(':') ? ip.split(':')[0] : ip22hub = '127.0.0.1'23hub_port = '4444'24hub_position = input_array.index((input_array & ['-h', '--hub']).first) || nil25foreground_values = ['-f', '--foreground']26run_foreground = (input_array & foreground_values).any? ? true : false27if hub_position28 hub = input_array[hub_position + 1]29 hub_orig = hub30 if hub.count(':') == 231 hub = hub_orig.rpartition(':').first32 hub_port = hub_orig.rpartition(':').last33 elsif hub.count(':') == 1 && !hub.include?('http')34 hub = hub_orig.split(':').first35 hub_port = hub_orig.split(':').last36 end37 if hub_port.count("a-zA-Z") > 038 raise 'Your ports must include numbers only'39 end40end41if input_array.include? '--restart'42 restart_devices43else44 platform = get_platform()45 if platform == :linux46 nodeConfigDir = File.expand_path('~/AppiumConnect/')47 elsif platform == :mac48 nodeConfigDir = File.expand_path('~/AppiumConnect/')49 elsif platform == :windows50 nodeConfigDir = Dir.home() + '/AppiumConnect'51 end52 create_dir nodeConfigDir53 create_dir nodeConfigDir + '/node_configs'54 create_dir nodeConfigDir + '/output'55 launch_hub_and_nodes ip, hub, hub_port, run_foreground, nodeConfigDir, host_port56end...

Full Screen

Full Screen

default.rb

Source:default.rb Github

copy

Full Screen

...9# Domain10default['fis-dotcom-v3']['domain_name'] = default_values['fis-dotcom-v3']['domain_name']11# Platforms12default['fis-dotcom-v3']['db_platform_suite'] = default_values['fis-dotcom-v3']['db_platform_suite']13default['fis-dotcom-v3']['db_platform_ip'] = default_values['fis-dotcom-v3']['db_platform_ip']14default['fis-dotcom-v3']['db_platform_ip_internal'] = default_values['fis-dotcom-v3']['db_platform_ip_internal']15default['fis-dotcom-v3']['web_platform_suite'] = default_values['fis-dotcom-v3']['web_platform_suite']16default['fis-dotcom-v3']['web_platform_ip'] = default_values['fis-dotcom-v3']['web_platform_ip']17default['fis-dotcom-v3']['web_platform_ip_internal'] = default_values['fis-dotcom-v3']['web_platform_ip_internal']18default['fis-dotcom-v3']['cache_platform_suite'] = default_values['fis-dotcom-v3']['cache_platform_suite']19default['fis-dotcom-v3']['cache_platform_ip'] = default_values['fis-dotcom-v3']['cache_platform_ip']20default['fis-dotcom-v3']['cache_platform_ip_internal'] = default_values['fis-dotcom-v3']['cache_platform_ip_internal']21# DB22default['fis-dotcom-v3']['mysql_root_password'] = default_values['fis-dotcom-v3']['mysql_root_password']23# Papertrail24# set['papertrail']['port'] = 5675825# set['papertrail']['host'] = 'logs2'26# set['papertrail']['certificate_checksum'] = '7019189e20ed695e9092e67d91a3b37249474f4c4c6355193ce6d2cb648f147c'27end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful