1. Get page HTML code based on URL request
/// <summary>///get HTML code for a Web page/// </summary>/// <param name= "url" >Link Address</param>/// <param name= "encoding" >Encoding Type</param>/// <returns></returns> Public Static stringGETHTMLSTR (stringUrlstringencoding) { stringHtmlstr =""; if(!string.isnullorempty (URL)) {WebRequest Request= WebRequest.Create (URL);//instantiating a WebRequest objectWebResponse response = Request. GetResponse ();//Create a WebResponse objectStream datastream = Response. GetResponseStream ();//creating a Stream objectEncoding EC =Encoding.default; if(Encoding = ="UTF8") {EC=Encoding.UTF8; } Else if(Encoding = ="Default") {EC=Encoding.default; } StreamReader Reader=NewStreamReader (datastream, EC); Htmlstr= Reader. ReadToEnd ();//reading DataReader. Close (); DataStream. Close (); Response. Close (); } returnhtmlstr;}
2. Download website pictures
/// <summary>///Download website Pictures/// </summary>/// <param name= "Picurl" ></param>/// <returns></returns> Public stringSaveaswebimg (stringPicurl) { stringresult =""; stringPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase +@"/file/";//Catalogue Try { if(!String.IsNullOrEmpty (Picurl)) {Random rd=NewRandom (); DateTime Nowtime=DateTime.Now; stringFileName = nowTime.Month.ToString () + nowTime.Day.ToString () + nowTime.Hour.ToString () + nowTime.Minute.ToString () + NowTime.Second.ToString () + Rd. Next ( +,1000000) +". JPEG"; WebClient WebClient=NewWebClient (); Webclient.downloadfile (Picurl, Path+fileName); Result=FileName; } } Catch { } returnresult;}
3. Get the local IP address
/// <summary> ///get local IP address information/// </summary> Public stringGetaddressip () {///get the local IP address stringAddressip =string. Empty; foreach(IPAddress _ipaddressinchDns.gethostentry (Dns.gethostname ()). AddressList) {if(_ipaddress.addressfamily.tostring () = ="Internetwork") {Addressip=_ipaddress.tostring (); } } returnaddressip.tostring (); }
C # Gets the HTML code of the Web page, downloads the web site picture, gets the IP address