Advertisement
prog

QRZ.com

Jul 11th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getQRZSession(login, password)
  2. {
  3.   // Retrieve stage 1 login tokens
  4.   var xhr = new ActiveXObject("Msxml2.XMLHTTP");
  5.   xhr.open("GET","http://www.qrz.com/",false);
  6.   xhr.send(null);
  7.   var content = xhr.responseText;
  8.   var action = "";
  9.   if (!/<form id="cmdbar" action="(\/li\/[0-9]+)" m/.test(content))
  10.   {
  11.     return false;
  12.   }
  13.   action = RegExp.$1;
  14.   var refr = action;
  15.  
  16.   // Retrieve stage 2 login tokens
  17.   xhr.open("POST","http://www.qrz.com" + action, false);
  18.   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  19.   xhr.send('refr=/&refcs=&cmdLogin=Login');
  20.   content = xhr.responseText.replace(/\n/g, " ");
  21.   if (!/<form name="loginform" action="(\/li\/[0-9]+)" .* name="s" value="([a-z0-9]+)"/.test(content))
  22.   {
  23.     return false;
  24.   }
  25.   action = RegExp.$1;
  26.   var s = RegExp.$2;
  27.  
  28.   // Log in
  29.   xhr.open("POST","http://www.qrz.com" + action, false);
  30.   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  31.   xhr.send('refr=' + refr + '&s=' + s + '&username=' + login + '&password=' + password);
  32.   content = xhr.responseText;
  33.  
  34.   if (!/Login Success/.test(content))
  35.   {
  36.     return false;
  37.   }
  38.  
  39.   return true;
  40. }
  41.  
  42. function getQRZInfo(callSign, login, password)
  43. {
  44.   var xhr = new ActiveXObject("Msxml2.XMLHTTP");
  45.   xhr.open("POST","http://www.qrz.com/db/",false);
  46.   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  47.   xhr.send("callsign=" + escape(callSign));
  48.   var content = xhr.responseText.replace(/\n/g, " ");
  49.  
  50.   if (/produced no results/.test(content))
  51.   {
  52.     return "No results";
  53.   }
  54.  
  55.   if (/Login is required for additional detail/.test(content))
  56.   {
  57.     if (!getQRZSession(login, password))
  58.     {
  59.       return "Cannot login to QRZ.com";
  60.     }
  61.     xhr.open("POST","http://www.qrz.com/db/",false);
  62.     xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  63.     xhr.send("callsign=" + escape(callSign));
  64.     content = xhr.responseText.replace(/\n/g, " ");
  65.   }
  66.  
  67.   if (/Service limit exceeded/.test(content))
  68.   {
  69.     return "QRZ service limit exceeded";
  70.   }
  71.  
  72.   if (!/"Click for Mailing Label">(.*)<b>Lookups: &nbsp; [0-9]+<\/b>/.test(content))
  73.   {
  74.     return "QRZ returned an unexpected result";
  75.   }
  76.  
  77.   var address = RegExp.$1.replace(/&nbsp; /g, "").replace(/<.+?>/g, "");
  78.  
  79.   return address;
  80. }
  81.  
  82. WScript.Echo(getQRZInfo("c4ll", "login", "password"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement