コード例 #1
0
ファイル: IP.cs プロジェクト: 1-EXON/Discord-Profile
        public static void GetExternalIP()
        {
            string searchIpFromUrl = new System.Net.WebClient().DownloadString(("http://checkip.dyndns.org"));
            string EtcIpInfo       = searchIpFromUrl.Substring(searchIpFromUrl.IndexOf("</body>"), searchIpFromUrl.Length - searchIpFromUrl.IndexOf("</body>"));

            string ExternalIp = searchIpFromUrl.Substring(searchIpFromUrl.IndexOf(":") + 1, searchIpFromUrl.Length - searchIpFromUrl.IndexOf(":") - EtcIpInfo.Length - 1).Trim();

            Data.externalIP = ExternalIp;
            Console.WriteLine(Data.externalIP);
        }
コード例 #2
0
 public MainTextFetcher(string URL, string startingEnclosure, string endingEnclosure)
 {
     //Download the HTML code from given URL
     string fetchedHTML = new WebClient().DownloadString(URL).ToString();
     //Search for the first occurance of first tag
     int firstPos = fetchedHTML.IndexOf(startingEnclosure);
     int secondPos = fetchedHTML.IndexOf(endingEnclosure, firstPos);
     //Fetch only the text of interest
     mainText = fetchedHTML.Substring(firstPos + startingEnclosure.Length, secondPos - firstPos - startingEnclosure.Length);
 }
コード例 #3
0
ファイル: RSSreader.cs プロジェクト: zeav/ProgTek-WebCrawler
 /// <summary>
 /// Fetches text from a website and gets only the text between the two Tags.
 /// </summary>
 /// <param name="URL">Website URL (with HTTP)</param>
 /// <param name="startingEnclosure">Starting Tag</param>
 /// <param name="endingEnclosure">Stop Tag</param>
 /// <returns></returns>
 public string MainTextFetcher(string URL, string startingEnclosure, string endingEnclosure)
 {
     //Download the HTML code from given URL
     string fetchedHTML = new WebClient().DownloadString(URL).ToString();
     //Search for the first occurance of first tag
     int firstPos = fetchedHTML.IndexOf(startingEnclosure);
     if (firstPos < 0) { Console.WriteLine("Main text fetch failed (1)."); return ""; }
     int secondPos = fetchedHTML.IndexOf(endingEnclosure, firstPos);
     if (secondPos < 0) { Console.WriteLine("Main text fetch failed (2)."); return ""; }
     //Fetch only the text of interest
     return fetchedHTML.Substring(firstPos + startingEnclosure.Length, secondPos - firstPos - startingEnclosure.Length);
 }
コード例 #4
0
ファイル: formLoginForm.cs プロジェクト: solsetmary/Makhzan
 private bool CheckForInternetConnection()
 {
     try
     {
         string str = new WebClient().DownloadString("http://labpp.org/check/internet/connection/");
         int posStart = str.IndexOf("PublicIP\":\"") + 11;
         int posEnd = str.IndexOf("\"}]");
         string newIP = str.Substring(posStart, posEnd - posStart);
         return true;
     }
     catch
     {
         return false;
     }
 }
コード例 #5
0
ファイル: SpecUtils.cs プロジェクト: kampfi/SAwarenessBeta
 static void GetSpecInfo()
 {
     String GameInfo = new WebClient().DownloadString(BaseUrl + RegionTag + UrlPartial + ObjectManager.Player.Name);
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(SearchString) + SearchString.Length);
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
     Key = GameInfo.Substring(0, GameInfo.IndexOf(" "));
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
     GameId = GameInfo.Substring(0, GameInfo.IndexOf(" "));
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
     PlatformId = GameInfo.Substring(0, GameInfo.IndexOf(" "));
 }
コード例 #6
0
ファイル: OEmbedController.cs プロジェクト: jgtaveras/Coevery
        public ActionResult Index(string folderPath, string url) {
            var viewModel = new OEmbedViewModel {
                Url = url,
                FolderPath = folderPath
            };

            try {
                // <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed">

                var source = new WebClient().DownloadString(url);

                // seek type="text/xml+oembed" or application/xml+oembed
                var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                if (oembedSignature == -1) {
                    oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                }
                if (oembedSignature != -1) {
                    var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<');
                    var tagEnd = source.IndexOf('>', oembedSignature);
                    var tag = source.Substring(tagStart, tagEnd - tagStart);
                    var matches = new Regex("href=\"([^\"]+)\"").Matches(tag);
                    if (matches.Count > 0) {
                        var href = matches[0].Groups[1].Value;
                        try {
                            var content = new WebClient().DownloadString(Server.HtmlDecode(href));
                            viewModel.Content = XDocument.Parse(content);
                        }
                        catch {
                            // bubble exception
                        }
                    }
                }
            }
            catch {
                return View(viewModel);
            }

            return View(viewModel);
        }
コード例 #7
0
ファイル: classWeather.cs プロジェクト: Winterstark/Adjutant
        public static string GetWebcamImage(string webcamsTravelURL)
        {
            try
            {
                string page = new WebClient().DownloadString(webcamsTravelURL);

                int lb = page.IndexOf("http://images.webcams.travel/thumbnail/");
                if (lb == -1)
                    return "";
                else
                {
                    int ub = page.IndexOf('"', lb);
                    if (ub == -1)
                        return "";
                    else
                        return page.Substring(lb, ub - lb).Replace("/thumbnail/", "/webcam/");
                }
            }
            catch (Exception exc)
            {
                Exception = exc;
                return "";
            }
        }
コード例 #8
0
ファイル: [PA 4] Robots.cs プロジェクト: kxchiu/INFO344
        public Robots(string authority)
        {
            string robotsTXTURL = authority + "/robots.txt";
            content = new WebClient().DownloadString(robotsTXTURL);

            int index = content.IndexOf("User-agent: *");
            if (index >= 0)
            {
                string disallowedContent = content.Substring(index);
                foreach (Match match in Regex.Matches(disallowedContent, @"Disallow:\s*([/-_.A-Za-z0-9]+)"))
                {
                    disallowed.Add(Urls.BuildAbsUrl(robotsTXTURL, match.Groups[1].Value));
                }
            }

            excludeUrlsWithoutToken = "";
        }
コード例 #9
0
        public static Decimal ConvertFromTo(string fromCurrency, string toCurrency)
        {
            if (!AllSymbols().Contains(fromCurrency))
                throw new CurrencyDoesNotExistException(fromCurrency);
            if (!AllSymbols().Contains(toCurrency))
                throw new CurrencyDoesNotExistException(toCurrency);
            var url = String.Format(
                "http://www.gocurrency.com/v2/dorate.php?"
                + "inV=1&from={0}&to={1}&Calculate=Convert",
                fromCurrency, toCurrency);
            var client = new WebClient();
            var result = new WebClient().DownloadString(url);

            var index = result.IndexOf("<div id=\"converter_results\"><ul><li>");
            var theGoodStuff = result.Substring(index);
            var startIndex = theGoodStuff.IndexOf("<b>") + 3;
            var endIndex = theGoodStuff.IndexOf("</b>");
            var importantStuff = theGoodStuff.Substring(startIndex, endIndex - startIndex);
            var parts = importantStuff.Split('=');
            var almostValue = parts[1].Trim().Split(' ')[0];
            return Decimal.Parse(almostValue, new CultureInfo("en"));
        }
コード例 #10
0
ファイル: classWeather.cs プロジェクト: Winterstark/Adjutant
        public static Report[] GetForecast(string location, string language, bool metric, int nDays, bool hourly)
        {
            string url;
            if (!hourly)
                url = constructWeathermapURL("http://api.openweathermap.org/data/2.5/forecast/daily?q=", location, language, metric, nDays);
            else
                url = constructWeathermapURL("http://api.openweathermap.org/data/2.5/forecast?q=", location, language, metric, 0);

            string resp = new WebClient().DownloadString(url);
            resp = resp.Substring(resp.IndexOf("\"list\":[{") + 9);

            string[] segments = resp.Split(new string[] { "},{" }, StringSplitOptions.RemoveEmptyEntries);

            int n = segments.Length;
            if (hourly)
                n = Math.Min(n, 8 * nDays + 1);

            Report[] reports = new Report[n];
            for (int i = 0; i < n; i++)
                reports[i] = buildReport(segments[i], hourly, metric);

            return reports;
        }
コード例 #11
0
ファイル: Usps.cs プロジェクト: AzarinSergey/learn
        private List<ShippingOption> GetShippingOption()
        {
            string request = _isDomenic
                ? UrlDomenic + GetXmlDomenicPackage()
                : UrlInternational + GetXmlInternationalPackage();

            string xml = new WebClient().DownloadString(request);
            if (xml.Contains("<Error>"))
            {
                int idx1 = xml.IndexOf("<Description>") + 13;
                int idx2 = xml.IndexOf("</Description>");
                string errorText = xml.Substring(idx1, idx2 - idx1);

                Debug.LogError(new Exception("USPS Error returned: " + errorText), false);
            }

            return ParseResponseMessage(xml);
        }
コード例 #12
0
ファイル: ServerSocket.cs プロジェクト: LukeByun/Launcher
        public static string GetMyOutsideIp()
        {
            try
            {
                #region 자신 외부 IP 가져오기 1
                //string whatIsMyIp = "http://www.whatismyip.com/automation/n09230945.asp";
                //WebClient wc = new WebClient();
                //UTF8Encoding utf8 = new UTF8Encoding();
                //string requestHtml = "";

                //requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));

                //IPAddress externalIp = null;

                //externalIp = IPAddress.Parse(requestHtml);

                //string WanIp = externalIp.ToString();
                #endregion

                #region 자신 외부 IP 가져오기 2

                Uri siteUri = new Uri("http://www.lgnas.com/");

                //WebRequest wr = WebRequest.Create(siteUri);
                //string se = wr.Method.ToString();

                //string whatIsMyIp = "http://www.lgnas.com/";
                //WebClient client = new WebClient();

                //// Add a user agent header in case the
                //// requested URI contains a query.

                //client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

                //string reply = client.DownloadString(siteUri);

                //Stream data = client.OpenRead(siteUri);
                //StreamReader reader = new StreamReader(data);
                //string s = reader.ReadToEnd();
                //Console.WriteLine(s);
                //data.Close();
                //reader.Close();
                #endregion

                //URL에서 IP획득
                string searchIpFromUrl = new System.Net.WebClient().DownloadString(("http://checkip.dyndns.org"));
                //                string searchIpFromUrl = new System.Net.WebClient().DownloadString(("http://www.lgnas.com/"));

                //자를부분
                string EtcIpInfo = searchIpFromUrl.Substring(searchIpFromUrl.IndexOf("</body>"), searchIpFromUrl.Length - searchIpFromUrl.IndexOf("</body>"));

                //전체에서 시작점~ 전체길이-앞뒤자를부분
                string serverIp = searchIpFromUrl.Substring(searchIpFromUrl.IndexOf(":") + 1, searchIpFromUrl.Length - searchIpFromUrl.IndexOf(":") - EtcIpInfo.Length - 1).Trim();

                return(serverIp);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error GetMyOutsideIp : {0}", ex.Message);
            }
            return(null);
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: hurr/DelayClose
 private void SubmitCaptchaAsyncDoWork(object sender, DoWorkEventArgs e)
 {
     CSubmitCaptchaData argument = (CSubmitCaptchaData)e.Argument;
     string url = argument.url;
     DateTime tm = argument.tm;
     string str = "";
     try
     {
         str = new WebClient().DownloadString(url);
     }
     catch (Exception)
     {
         return;
     }
     if (str.IndexOf("Your answer was correct.") != -1 || str.IndexOf("Réponse correcte") != -1)//Add || and your local language here.
     {
         uint index = (uint)str.IndexOf("cols=\"100\">");
         uint num2 = (uint)str.IndexOf("<", (int)(((int)index) + 1));
         captchas.Add(new CCaptcha(str.Substring(((int)index) + 11, ((int)(num2 - index)) - 11), tm));
     }
 }
コード例 #14
0
        public object Get(string id, string feed = "feed", int limit = 20)
        {
            var appId = ConfigurationManager.AppSettings[Constants.FacebookAppIdKey];
            var appSecret = ConfigurationManager.AppSettings[Constants.FacebookAppSecretKey];

            var pageId = id;

            if (limit > 250)
                limit = 250;

            const string fields = "id,message,picture,link,name,description,type,icon,created_time,from,object_id,likes,comments";

            var authUrl = $"https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={appId}&client_secret={appSecret}";

            var accessToken = new WebClient().DownloadString(authUrl);
            accessToken = accessToken.Substring(accessToken.IndexOf('=') + 1);

            var pageUrl = $"https://graph.facebook.com/v2.3/{pageId}?key=value&access_token={accessToken}&fields=id,link,name";

            var pageObject = new WebClient().DownloadString(pageUrl);

            dynamic pageDetails = JObject.Parse(pageObject);

            var pageLink = pageDetails.link ?? string.Empty;
            var pageName = pageDetails.name ?? string.Empty;

            var graphUrl = $"https://graph.facebook.com/v2.3/{pageId}/{feed}?key=value&access_token={accessToken}&fields={fields}&limit={limit}";
            var graphObject = new WebClient().DownloadString(graphUrl);
            dynamic parsedJson = JObject.Parse(graphObject);
            var pagefeed = parsedJson.data;

            var response = new
            {
                responseData = new {
                    feed = new {
                        link = string.Empty,
                        entries = new List<dynamic>()
                    }
                }
            };

            foreach (var data in pagefeed)
            {
                string message;
                if (!string.IsNullOrEmpty((string)data.message))
                {
                    message = ((string) data.message).Replace("\n", "<br />");
                }
                else if (!string.IsNullOrEmpty((string)data.story))
                {
                    message = data.story;
                }
                else
                {
                    message = string.Empty;
                }

                if (!string.IsNullOrEmpty((string)data.description))
                {
                    message += " " + data.description;
                }

                string link = data.link ?? string.Empty;
                string image = data.picture ?? string.Empty;
                string type = data.type ?? string.Empty;

                if (type == "status" && !string.IsNullOrEmpty((string)data.story))
                {
                    continue;
                }

                if ((data.object_id == null) && (type != "video"))
                {
                    var picId = image.Split('_');
                    if (picId.Length > 0)
                    {
                        data.object_id = picId[0];
                    }
                }

                if (data.object_id != null)
                {
                    if (!image.Contains("safe_image.php") && Regex.IsMatch((string)data.object_id, @"^\d+$"))
                    {
                        image = $"https://graph.facebook.com/{data.object_id}/picture?type=normal";
                    }
                }

                response.responseData.feed.entries.Add(new {
                    pageLink,
                    pageName,
                    link,
                    content = message,
                    thumb = image,
                    data.comments,
                    publishedDate = data.created_time //might need to change, original PHP date format: D, d M Y H:i:s O
                });
            }

            return response;
        }
コード例 #15
0
        public static string WebsiteTranslate(string input, string sourceLanguage, string targetLanguage)
        {
            input = input.Replace(Environment.NewLine, "<br/>");
            input = input.Replace("'", "&apos;");
            string address = string.Format("http://translate.google.com/?hl=en&eotf=1&sl={0}&tl={1}&q={2}", sourceLanguage, targetLanguage, 
                HttpUtility.UrlEncode(input));

            string str2 = "";

            try
            {
                str2 = new WebClient 
                { 
                    Proxy = null, 
                    Encoding = Encoding.Default 
                }.DownloadString(address);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                str2 = input;
            }

            Encoding enc = Encoding.Default;
            StringBuilder builder = new StringBuilder();
            int index = str2.IndexOf("charset=");
            if (index > 0)
            {
                int idx2 = str2.IndexOf("\"", index);
                if (idx2 > 0)
                {
                    enc = Encoding.GetEncoding(str2.Substring(index + 8, (idx2 - index) - 8).ToLowerInvariant().Trim());
                }
            }
            index = str2.IndexOf("<span id=result_box");
            if (index > 0)
            {
                index = str2.IndexOf("<span title=", index);
                while (index > 0)
                {
                    index = str2.IndexOf(">", index);
                    if (index > 0)
                    {
                        index++;
                        int num2 = str2.IndexOf("</span>", index);
                        string str15 = str2.Substring(index, num2 - index);
                        string str4 = HttpUtility.HtmlDecode(enc.GetString(Encoding.Default.GetBytes(str15))).Replace(" </ P>", "</ p>").Replace(" <P>", "<p>").Replace(" <P >", "<p>").Replace(" < P >", "<p>").Replace(" </ p>", "</p>").Replace("</ p>", "</p>").Replace("</ P>", "</p>").Replace("</P>", "</p>").Replace("< /P >", "</p>");
                        builder.Append(str4);
                        index = str2.IndexOf("<span title=", index);
                    }
                }
            }
            string str5 = builder.ToString().Replace(" <br/>", Environment.NewLine).Replace("<br/>", Environment.NewLine).Replace("<br />", Environment.NewLine).Replace("< p >", "<p>").Replace("< p>", "<p>").Replace("<p >", "<p>").Replace("</ p>", "</p>").Replace("< / p >", "</p>").Replace("< / p>", "</p>").Replace(" </p>", "</p>").Replace(" </p>", "</p>").Replace("</p>  ", "</p>").Replace("</p> ", "</p>").Replace("</p> ", "</p>").Replace("</p><p>", "@__P_TAG").Replace("</p>", "</p><p>").Replace("@__P_TAG", "</p><p>");
            int length = str5.LastIndexOf("<p>");
            if (length > 0)
            {
                str5 = str5.Substring(0, length);
            }
            return str5;
        }
コード例 #16
0
ファイル: classReddit.cs プロジェクト: Winterstark/Adjutant
            public Post(string title, string url, string permalink, string user, string subreddit, string score, string nComments, string created, string thumbnail)
            {
                this.title = title;
                this.url = url;
                this.permalink = "http://www.reddit.com" + permalink;
                this.user = user;
                this.subreddit = "/r/" + subreddit;
                this.score = int.Parse(score);
                this.nComments = int.Parse(nComments);
                this.created = Misc.ConvertFromUnixTime(created);

                if (url.Contains("imgur") && !url.Contains("imgur.com/a/"))
                {
                    if (url[url.Length - 4] != '.')
                    {
                        //find image extension
                        if (url.Contains("/gallery/"))
                            url = url.Replace("/gallery/", "/");

                        url = "http://api.imgur.com/oembed.json?url=" + url;

                        string jsonFile = new WebClient().DownloadString(url);

                        if (jsonFile.Contains("\"url\":\""))
                        {
                            int lb = jsonFile.IndexOf("\"url\":\"") + 7;
                            int ub = jsonFile.IndexOf('"', lb);
                            url =  jsonFile.Substring(lb, ub - lb);
                            url = Regex.Unescape(url);
                        }
                        else
                        {
                            //no extension data present in xml file
                            url = this.url; //reset url

                            if (thumbnail != "")
                                image = "<image=" + thumbnail + ">"; //use thumbnail
                            else
                                image = "";
                            return;
                        }
                    }

                    if (!url.Contains("i."))
                        url = url.Replace("imgur.com", "i.imgur.com");

                    url = url.Insert(url.Length - 4, "l"); //download large version

                    image = "<image=" + url + ">";
                }
                else
                    image = "<image=" + thumbnail + ">";
            }
コード例 #17
0
ファイル: MainWindow.cs プロジェクト: JulyMoon/paperwallz
        private static string Wallhaven(string url)
        {
            if (Regex.IsMatch(url, @"http://alpha.wallhaven.cc/wallpaper/\d+"))
            {
                string contents = new WebClient().DownloadString(url);
                int index = contents.IndexOf(@"content=""//", StringComparison.Ordinal);
                if (index != -1)
                {
                    index += 9;
                    return "http:" + contents.Substring(index,
                               contents.IndexOf(@"""", index, StringComparison.Ordinal) - index);
                }

                throw new Exception("Perhaps wallhaven changed their html pages?");
            }

            return url;
        }