407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
# File 'lib/nicinfo/nicinfo_main.rb', line 407
def run
@config.logger.
@config.logger.mesg(NicInfo::VERSION_LABEL, NicInfo::AttentionType::PRIMARY )
@config.setup_workspace
@config.check_config_version
@cache = Cache.new(@config)
@cache.clean if @config.config[ NicInfo::CACHE ][ NicInfo::CLEAN_CACHE ]
if @config.options.empty_cache
@cache.empty
end
if @config.options.get_iana_files
get_iana_files
else
check_bsfiles_age = @config.check_bsfiles_age?
update_bsfiles = @config.update_bsfiles?( check_bsfiles_age )
if update_bsfiles
@config.logger.mesg( "IANA RDAP bootstrap files are old and need to be updated.", NicInfo::AttentionType::ERROR )
get_iana_files
elsif check_bsfiles_age
@config.logger.mesg( "IANA RDAP bootstrap files are old. Update them with --iana option", NicInfo::AttentionType::ERROR )
end
end
if @config.options.demo
@config.logger.mesg( "Populating cache with demonstration results", NicInfo::AttentionType::INFO )
@config.logger.mesg( "Try the following demonstration queries:", NicInfo::AttentionType::INFO )
demo_dir = File.join( File.dirname( __FILE__ ), NicInfo::DEMO_DIR )
demo_files = Dir::entries( demo_dir )
demo_files.each do |file|
df = File.join( demo_dir, file )
if File.file?( df )
demo_data = File.read( df )
json_data = JSON.load demo_data
demo_url = json_data[ NicInfo::NICINFO_DEMO_URL ]
demo_hint = json_data[ NicInfo::NICINFO_DEMO_HINT ]
@cache.create( demo_url, demo_data )
@config.logger.mesg( " " + demo_hint, NicInfo::AttentionType::INFO )
end
end
end
if @config.options.help
help()
end
if @config.options.argv == nil || @config.options.argv == [] && !@config.options.query_type
unless @config.options.require_query
return
else
help
end
end
if @config.options.argv[0] == '.'
@config.logger.mesg( "Obtaining current IP Address...")
data = get("https://stat.ripe.net/data/whats-my-ip/data.json", 0, false )
json_data = JSON.load(data)
if json_data["data"] == nil || json_data["data"]["ip"] == nil
@config.logger.mesg("Server repsonded with unknown JSON")
@config.logger.mesg("Unable to determine your IP Address. You must specify it.")
return
elsif
@config.logger.mesg("Your IP address is " + json_data["data"]["ip"], NicInfo::AttentionType::SUCCESS )
@config.options.argv[0] = json_data["data"]["ip"]
end
end
if @config.options.query_type == nil
@config.options.query_type = guess_query_value_type(@config.options.argv)
if (@config.options.query_type == QueryType::BY_IP4_ADDR ||
@config.options.query_type == QueryType::BY_IP6_ADDR ) && @config.options.reverse_ip == true
ip = IPAddr.new( @config.options.argv[ 0 ] )
@config.options.argv[ 0 ] = ip.reverse.split( "\." )[ 1..-1 ].join( "." ) if ip.ipv4?
@config.options.argv[ 0 ] = ip.reverse.split( "\." )[ 24..-1 ].join( "." ) if ip.ipv6?
@config.logger.mesg( "Query value changed to " + @config.options.argv[ 0 ] )
@config.options.query_type = QueryType::BY_DOMAIN
@config.options.externally_queriable = true
elsif @config.options.query_type == QueryType::BY_RESULT
data_tree = @config.load_as_yaml( NicInfo::LASTTREE_YAML )
node = data_tree.find_node( @config.options.argv[ 0 ] )
if node and node.rest_ref
@config.options.argv[ 0 ] = node.rest_ref
@config.options.url = true
if node.data_type
@config.options.query_type = node.data_type
@config.options.externally_queriable = false
elsif node.rest_ref
@config.options.query_type = get_query_type_from_url( node.rest_ref )
@config.options.externally_queriable = true
end
else
@config.logger.mesg( "#{@config.options.argv[0]} is not retrievable.")
return
end
elsif @config.options.query_type == QueryType::BY_URL
@config.options.url = @config.options.argv[0]
@config.options.query_type = get_query_type_from_url( @config.options.url )
else
@config.options.externally_queriable = true
end
if @config.options.query_type == nil
@config.logger.mesg("Unable to guess type of query. You must specify it.")
return
else
@config.logger.trace("Assuming query value is " + @config.options.query_type)
end
end
qtype = @config.options.query_type
case qtype
when QueryType::TRACE
ips = NicInfo.traceroute @config.options.argv[ 0 ], @config
if ips.empty?
@config.logger.mesg "Trace route yeilded no data"
else
ips.each do |ip|
@config.options.query_type = QueryType::BY_IP4_ADDR
@config.options.argv[ 0 ] = ip
@config.config[ NicInfo::BOOTSTRAP ][ NicInfo::BOOTSTRAP_URL ] = nil
json_data = do_rdap_query
display_rdap_query( json_data, false )
end
end
else
json_data = do_rdap_query
display_rdap_query( json_data, true ) if json_data
end
end
|