Compare commits

...

4 Commits

Author SHA1 Message Date
준영 김
e8d6a59565 ncsi이용해서 네트워크 상태 구현함 2024-05-08 21:15:05 +09:00
준영 김
eb69a3cf12 Modified 2024-05-08 21:00:27 +09:00
준영 김
723858ec9b Modified 2024-05-08 20:01:25 +09:00
junyoung kim
50772dedf9
Update UserControl1.cs
Add network status
2024-04-15 19:33:32 +09:00
2 changed files with 53 additions and 5 deletions

View File

@ -1,7 +1,11 @@
using Catswords.DataType.Client.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text;
using System.Windows.Forms;
using System.Xml;
@ -17,6 +21,7 @@ namespace Catswords.DataType.Client.Helper
Indicators = new List<Indicator>();
}
public void Fetch(string q)
{
try
@ -24,6 +29,7 @@ namespace Catswords.DataType.Client.Helper
// 원격 주소에서 XML 다운로드
string url = Config.SEARCH_URL + q;
WebClient client = new WebClient();
client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3");
client.Encoding = Encoding.UTF8;
string xmlString = client.DownloadString(url);

View File

@ -1,4 +1,4 @@
using Catswords.DataType.Client.Helper;
using Catswords.DataType.Client.Helper;
using Catswords.DataType.Client.Model;
using System;
using System.ComponentModel.Design;
@ -6,6 +6,7 @@ using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;
namespace Catswords.DataType.Client
@ -81,14 +82,55 @@ namespace Catswords.DataType.Client
ExtractLink();
}
bool IsInternetConnected()
{
const string NCSI_TEST_URL = "http://www.msftncsi.com/ncsi.txt";
const string NCSI_DNS = "dns.msftncsi.com";
const string NCSI_DNS_IP_ADDRESS = "131.107.255.255";
try
{
// Check NCSI test link
var webClient = new WebClient();
string result = webClient.DownloadString(NCSI_TEST_URL);
if (result != "Microsoft NCSI")
{
return false;
}
// Check NCSI DNS IP
var dnsHost = Dns.GetHostEntry(NCSI_DNS);
if (dnsHost.AddressList.Count() < 0 || dnsHost.AddressList[0].ToString() != NCSI_DNS_IP_ADDRESS)
{
return false;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return false;
}
return true;
}
private void FetchFromFileExtensionDB()
{
var search = new FileExtensionDB();
search.Fetch(fileExtension);
foreach (Indicator ind in search.Indicators)
if (IsInternetConnected())
{
listView1.Items.Add(new ListViewItem(new string[] { ind.CreatedAt.ToString(), ind.Content }, 0));
var search = new FileExtensionDB();
search.Fetch(fileExtension);
foreach (Indicator ind in search.Indicators)
{
listView1.Items.Add(new ListViewItem(new string[] { ind.CreatedAt.ToString(), ind.Content }, 0));
}
} else
{
MessageBox.Show("인터넷에 연결되어 있지 않습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void FetchFromTimeline()