Skip to content

Instantly share code, notes, and snippets.

@system123
Last active February 13, 2018 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save system123/952b2dc1426379977779bdba988ec6cd to your computer and use it in GitHub Desktop.
Save system123/952b2dc1426379977779bdba988ec6cd to your computer and use it in GitHub Desktop.
A brute force to find lost DHL tracking numbers when the receipt has deteriorated and only a few digits are readable
require "net/http"
require 'parallel'
start = "54608206666?"
start = "54608??????4"
def make_tracking_num(i, start)
n = start.count("?")
missing = sprintf("%0#{n}d" % i).split('')
track = start.gsub '?', '%d'
track = sprintf(track % missing)
return(track)
end
def is_valid_tracking_num?(track)
resp = Net::HTTP.get(URI("https://nolp.dhl.de/nextt-online-public/en/search?piececode=#{track}")).index('09.12.17 09:38')
return(!resp.nil?)
end
valid = []
n = start.count("?")
to = ("9"*n).to_i
# Shuffle as going in order is less beneficial for end cases, so we rather make everything equally likely
posibilities = (0..to).map{|i| make_tracking_num(i, start) }.shuffle
Parallel.map(posibilities, progress: "Doing stuff",in_processes: 4) do |tn|
def test(track)
resp = Net::HTTP.get(URI("https://nolp.dhl.de/nextt-online-public/en/search?piececode=#{track}"))
if resp.index('shipment').nil?
puts "Something is wrong!!!!"
return(nil)
end
return(resp)
end
resp = test(tn)
if resp.nil?
sleep(1)
resp = test(tn)
end
match = resp.index('09.12.17 09')
puts "Found: #{tn}" if !match.nil?
sleep 0.1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment