Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit da7a83a

Browse files
author
Andy Newton
committed
fixed self IP lookup warning bug
1 parent a6a6429 commit da7a83a

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ with the latest RDAP specifications.
117117
* Changed default pager to `more` from `less`
118118
* 1.2.1
119119
* Updated asn.json and dns.json bootstrap files from IANA.
120+
* Fixed small bug in self IP lookup which incorrectly expected RIPE stat to be an RDAP server.
120121

121122
# System Requirements
122123

lib/nicinfo/nicinfo_main.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def make_rdap_url( base_url, resource_path )
285285
end
286286

287287
# Do an HTTP GET with the path.
288-
def get url, try
288+
def get url, try, expect_rdap = true
289289

290290
data = @cache.get(url)
291291
if data == nil
@@ -310,7 +310,7 @@ def get url, try
310310
if @config.config[ NicInfo::SECURITY ][ NicInfo::TRY_INSECURE ]
311311
@config.logger.mesg( "Secure connection failed. Trying insecure connection." )
312312
uri.scheme = "http"
313-
return get( uri.to_s, try )
313+
return get( uri.to_s, try, expect_rdap )
314314
else
315315
raise e
316316
end
@@ -319,19 +319,21 @@ def get url, try
319319
case res
320320
when Net::HTTPSuccess
321321
content_type = res[ "content-type" ].downcase
322-
unless content_type.include?(NicInfo::RDAP_CONTENT_TYPE) or content_type.include?(NicInfo::JSON_CONTENT_TYPE)
323-
raise Net::HTTPServerException.new("Bad Content Type", res)
324-
end
325-
if content_type.include? NicInfo::JSON_CONTENT_TYPE
326-
@config.conf_msgs << "Server responded with non-RDAP content type but it is JSON"
322+
if expect_rdap
323+
unless content_type.include?(NicInfo::RDAP_CONTENT_TYPE) or content_type.include?(NicInfo::JSON_CONTENT_TYPE)
324+
raise Net::HTTPServerException.new("Bad Content Type", res)
325+
end
326+
if content_type.include? NicInfo::JSON_CONTENT_TYPE
327+
@config.conf_msgs << "Server responded with non-RDAP content type but it is JSON"
328+
end
327329
end
328330
data = res.body
329331
@cache.create_or_update(url, data)
330332
else
331333
if res.code == "301" or res.code == "302" or res.code == "303" or res.code == "307" or res.code == "308"
332334
res.error! if try >= 5
333335
location = res["location"]
334-
return get( location, try + 1)
336+
return get( location, try + 1, expect_rdap)
335337
end
336338
res.error!
337339
end #end case
@@ -426,7 +428,7 @@ def run
426428

427429
if @config.options.argv[0] == '.'
428430
@config.logger.mesg( "Obtaining current IP Address...")
429-
data = get("https://stat.ripe.net/data/whats-my-ip/data.json", 0)
431+
data = get("https://stat.ripe.net/data/whats-my-ip/data.json", 0, false )
430432
json_data = JSON.load(data)
431433

432434
if json_data["data"] == nil || json_data["data"]["ip"] == nil

0 commit comments

Comments
 (0)