Hack Forums
[C#] [SNIP] HideMyAss Proxy Grabber - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] [SNIP] HideMyAss Proxy Grabber (/showthread.php?tid=2651628)



[SNIP] HideMyAss Proxy Grabber - soft2050 - Jul 6, 2012

Wrote this for this thread yesterday: https://hackforums.net/showthread.php?tid=2649418

Function:
PHP Code

<?php 
public static string[] grabProxy(string source)
  {
    
// Credits: Soft2050
    
var proxies = new List<string>();
    foreach (Match 
m in Regex.Matches(source, @"<td><span>([\s\S]*?)(\d+)</td>"))
    {
    
string port = m.Groups[2].Value;
    
string ip = m.Groups[1].Value;
    
ip = Regex.Replace(ip, @"(<(div|span) style=""display:none"">\d+.*?>|<.*?>)", "").Trim();
    
proxies.Add(string.Concat(ip, ":", port));
    }
    return 
proxies.ToArray();
  } 

Usage:
PHP Code

<?php 
static void Main(string[] args)
  {

    
WebClient wc = new WebClient();

    
string[] proxyList = grabProxy(wc.DownloadString("http://hidemyass.com/proxy-list/"));

    Array.ForEach(
proxyList, s => Console.WriteLine(s));

    
Console.ReadKey();

  } 

Edit: I just made a little function that will let you grab proxies upto (x) Pages specified by you:

PHP Code

<?php 
public static string[] grabHMAProxies(int uptoPages)
  {
    
// Credits: Soft2050
    
WebClient wc = new WebClient();
    var 
proxies = new List<string>();
    for (
int i = 1; i <= uptoPages; i++)
    {
    
proxies.AddRange(grabProxy(wc.DownloadString(string.Format("http://hidemyass.com/proxy-list/{0}", i))));
    }
    return 
proxies.ToArray();
  } 



* - dreamer66 - Jul 6, 2012

Ever thought of making your function get all the proxies from all the pages by the way ? Instead of just the selected page?

Just keep scanning pages from http://hidemyass.com/proxy-list/1 till it contains no more Regex matches (proxies).


* - soft2050 - Jul 6, 2012

Hehe, i did that already before your reply. You might have not seen the last function i guess 😉

[Image: cAGPk.png]

Although in that you have to specify end page 🙂


* - ‎Cloud - Jul 6, 2012

Wow, this seems really cool. It would be helpful if you could add comments explaining what the code does for beginner coders like myself. 👍


* - soft2050 - Jul 7, 2012

Ok, i am not so good at explaining but i tried what i could do:
PHP Code

<?php 
public static string[] grabProxy(string source)
{
    
// Credits: Soft2050
    
var proxies = new List<string>(); // creates a new list of string to return later
    
foreach (Match m in Regex.Matches(source, @"<td><span>([\s\S]*?)(\d+)</td>"))
    {
    
string port = m.Groups[2].Value;
    
string ip = m.Groups[1].Value;
    
ip = Regex.Replace(ip, @"(<(div|span) style=""display:none"">\d+.*?>|<.*?>)", "").Trim(); // replace extra html tags and hma's hidden divs from source
    
proxies.Add(string.Concat(ip, ":", port)); // add the ip address in a combined form of ip:port
    
}
    return 
proxies.ToArray(); // convert list of string to array and return it back
} 

PHP Code

<?php 
public static string[] grabHMAProxies(int uptoPages)
{
    
// Credits: Soft2050
    
WebClient wc = new WebClient(); // initialize a webclient to download source later, you could use your method of webrequest by replacing the DownloadString method in the below code
    
var proxies = new List<string>(); // creates a new list of string to return later
    
for (int i = 1; i <= uptoPages; i++) // loop until it added proxies from pages from 1 to uptoPages
    
{
    
proxies.AddRange(grabProxy(wc.DownloadString(string.Format("http://hidemyass.com/proxy-list/{0}", i)))); // AddRange - Adds a array to Array which is being returned by grabProxy function
    
}
    return 
proxies.ToArray(); // convert list of string to array and return it back
} 
Hope it helps


* - Pussy Cat - Jul 7, 2012

Posted the same thing few weeks ago, I guess the thread just got lost in old threads :\
https://hackforums.net/showthread.php?tid=2623574