/// <Summary> /// verify whether the proxy IP address is useful /// </Summary> /// <Param name = "ip"> ip address </param> /// <Param name = "Port"> port number </param> // <returns> returns true </returns> static bool isenabled (string IP, int port) {try {httpwebrequest Req = (httpwebrequest) webrequest. create ("http://www.whatismyip.com.tw/"); WebProxy proxyobject = new WebProxy (IP, Port); // ip address, port number req. proxy = proxyobject; // sets proxy req. useragent = "Mozilla/5. 0 (Windows NT 6.1; RV: 31.0) Gecko/20100101 Firefox/31.0 "; httpwebresponse resp = (httpwebresponse) req. getresponse (); encoding code = encoding. getencoding ("UTF-8"); Using (streamreader sr = new streamreader (resp. getresponsestream (), Code) {If (SR! = NULL) {string strhtml = Sr. readtoend (); matchcollection MC = RegEx. Matches (strhtml, "<H2> (? <Text> .*?) </H2> ", regexoptions. ignorecase); If (MC. count> 0) {groupcollection GC = mc [0]. groups; If (IP = GC ["text"]. value) {return true ;}}} catch {return false ;}
[Original] verify whether the proxy IP address is useful