1. 접속주소 난독화

2. 옵션 기능 추가
3. 리소스에 크롬 내포
4. 작업 디렉토리 설정
This commit is contained in:
2021-08-05 20:04:47 +09:00
parent a55addb24e
commit eceb815ed8
6 changed files with 321 additions and 114 deletions

View File

@@ -16,10 +16,38 @@ namespace NaverSearcher
{
private static Random m_Random = new Random();
WebSocket m_WebSocket = new WebSocket("ws://api.inrose.com");
private static readonly string x00 = "w";
private static readonly string x01 = "s";
private static readonly string x02 = ":";
private static readonly string x03 = "/";
private static readonly string x04 = "/";
private static readonly string x05 = "a";
private static readonly string x06 = "p";
private static readonly string x07 = "i";
private static readonly string x08 = ".";
private static readonly string x09 = "i";
private static readonly string x0A = "n";
private static readonly string x0B = "r";
private static readonly string x0C = "o";
private static readonly string x0D = "s";
private static readonly string x0E = "e";
private static readonly string x0F = ".";
private static readonly string x10 = "c";
private static readonly string x11 = "o";
private static readonly string x12 = "m";
private static readonly string xFF = (x00 + x01 + x02 + x03 + x04 + x05 + x06 + x07 + x08 + x09 + x0A + x0B + x0C + x0D + x0E + x0F + x10 + x11 + x12);
WebSocket m_WebSocket = new WebSocket(xFF);
Thread m_Thread = new Thread(NaverSearcherExcute);
private static uint optPageMoveWaitMin = 2000;
private static uint optPageMoveWaitMax = 3000;
private static uint optSearchWaitMin = 2000;
private static uint optSearchWaitMax = 6000;
public Form1()
{
InitializeComponent();
@@ -33,8 +61,41 @@ namespace NaverSearcher
{
JObject _JObject = JObject.Parse(e.Data);
if (_JObject.ContainsKey("keepalive"))
if (_JObject.ContainsKey("option"))
{
JObject _JObject_option = JObject.Parse(_JObject["option"].ToString());
if (_JObject_option.ContainsKey("PageMoveWaitMin"))
{
optPageMoveWaitMin = uint.Parse(_JObject_option.GetValue("PageMoveWaitMin").ToString());
if (optPageMoveWaitMin > optPageMoveWaitMax)
optPageMoveWaitMax = optPageMoveWaitMin;
}
if (_JObject_option.ContainsKey("PageMoveWaitMax"))
{
optPageMoveWaitMax = uint.Parse(_JObject_option.GetValue("PageMoveWaitMax").ToString());
if (optPageMoveWaitMax < optPageMoveWaitMin)
optPageMoveWaitMin = optPageMoveWaitMax;
}
if (_JObject_option.ContainsKey("SearchWaitMin"))
{
optSearchWaitMin = uint.Parse(_JObject_option.GetValue("SearchWaitMin").ToString());
if (optSearchWaitMin > optSearchWaitMax)
optSearchWaitMax = optSearchWaitMin;
}
if (_JObject_option.ContainsKey("SearchWaitMax"))
{
optSearchWaitMax = uint.Parse(_JObject_option.GetValue("SearchWaitMax").ToString());
if (optSearchWaitMax < optSearchWaitMin)
optSearchWaitMin = optSearchWaitMax;
}
}
if (_JObject.ContainsKey("key_pairs"))
@@ -45,6 +106,7 @@ namespace NaverSearcher
if (m_Thread.ThreadState == ThreadState.Stopped)
m_Thread = new Thread(NaverSearcherExcute);
m_Thread.IsBackground = true;
m_Thread.Start(_JObject);
}
};
@@ -200,6 +262,8 @@ namespace NaverSearcher
JObject _JObject = (JObject)_Object;
ChromeOptions _ChromeOptions = new ChromeOptions();
/*
_ChromeOptions.AddArguments("disable-infobars");
_ChromeOptions.AddArguments("--js-flags=--expose-gc");
_ChromeOptions.AddArguments("--enable-precise-memory-info");
@@ -207,6 +271,8 @@ namespace NaverSearcher
_ChromeOptions.AddArguments("--disable-default-apps");
_ChromeOptions.AddArguments("--headless");
_ChromeOptions.AddArguments("user - agent = Mozilla / 5.0(Macintosh; Intel Mac OS X 10_12_6) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 61.0.3163.100 Safari / 537.36");
*/
_ChromeOptions.BinaryLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch\\chrome.exe";
// 프록시 설정
//Proxy proxy = new Proxy();
@@ -220,12 +286,9 @@ namespace NaverSearcher
ChromeDriverService _ChromeDriverService = ChromeDriverService.CreateDefaultService();
_ChromeDriverService.HideCommandPromptWindow = true;
//_ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions);
ChromeDriver _ChromeDriver = new ChromeDriver();
ChromeDriver _ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions);
//_ChromeOptions.add_argument("user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(5));
try
{
@@ -275,13 +338,17 @@ namespace NaverSearcher
{
_query_elment.Clear();
_query_elment.SendKeys(item);
Thread.Sleep(m_Random.Next(500, 1000));
}
_query_elment.SendKeys(OpenQA.Selenium.Keys.Enter);
PageMoveWait(_ChromeDriver);
((IJavaScriptExecutor)_ChromeDriver).ExecuteScript("window.scrollBy(0, document.body.scrollHeight);");
Thread.Sleep(m_Random.Next(2000, 6000));
SearchWait(_ChromeDriver);
ReadOnlyCollection<IWebElement> links = _ChromeDriver.FindElements(By.CssSelector("a[href*='https://']"));
@@ -292,7 +359,6 @@ namespace NaverSearcher
try
{
int _sel = m_Random.Next(0, links.Count);
string kknd = links[_sel].GetAttribute("href");
links[_sel].Click();
break;
@@ -304,8 +370,11 @@ namespace NaverSearcher
}
} while (--_try > 0);
PageMoveWait(_ChromeDriver);
((IJavaScriptExecutor)_ChromeDriver).ExecuteScript("window.scrollBy(0, document.body.scrollHeight);");
Thread.Sleep(m_Random.Next(2000, 6000));
SearchWait(_ChromeDriver);
if (_ChromeDriver.WindowHandles.First() != _ChromeDriver.WindowHandles.Last())
{
@@ -364,108 +433,6 @@ namespace NaverSearcher
{
try
{
ChromeDriver _ChromeDriver = new ChromeDriver();
WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
foreach (var key_words in _JObject["key_pairs"])
{
// 로그인 여부 확인
// 로그아웃 실행
// 네이버 메인
// 스크롤 내린다.
// 20 ~ 60초 대기
try
{
_ChromeDriver.Navigate().GoToUrl(@"https://naver.com");
_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id=\"query\"]")));
string _logout = @"/html/body/div/div/div[1]/div[1]/a[1]";
if (IsElementPresent(_ChromeDriver, By.XPath(_logout)))
{
_ChromeDriver.FindElement(By.XPath(_logout)).Click();
}
foreach (var key_word in key_words["key_words"])
{
// 검색어 입력 (검색어 1)
// 검색어 확인
// 스크롤 내린다.
// 20 ~ 60초 대기
// 아무 게시글 클릭
// 이동된 페이지 작업
// 스크롤 내리기
// 20 ~ 60초 대기
// 새창 닫기
try
{
_ChromeDriver.Navigate().GoToUrl(@"https://naver.com");
string _query_xpath = "//*[@id=\"query\"]";
_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_query_xpath)));
IWebElement _query_elment = _ChromeDriver.FindElement(By.XPath(_query_xpath));
foreach (var item in StringParser.CharacterMakeHistory(key_word["key_word"].ToString()))
{
_query_elment.Clear();
_query_elment.SendKeys(item);
Thread.Sleep(m_Random.Next(500, 1000));
}
_query_elment.SendKeys(OpenQA.Selenium.Keys.Enter);
((IJavaScriptExecutor)_ChromeDriver).ExecuteScript("window.scrollBy(0, document.body.scrollHeight);");
Thread.Sleep(m_Random.Next(2000, 6000));
ReadOnlyCollection<IWebElement> links = _ChromeDriver.FindElements(By.CssSelector("a[href*='https://']"));
int _try = links.Count;
do
{
try
{
int _sel = m_Random.Next(0, links.Count);
string kknd = links[_sel].GetAttribute("href");
links[_sel].Click();
break;
}
catch (Exception ex)
{
Console.WriteLine("=== 무작위 링크 접속 ===");
Console.WriteLine(ex.Message);
}
} while (--_try > 0);
((IJavaScriptExecutor)_ChromeDriver).ExecuteScript("window.scrollBy(0, document.body.scrollHeight);");
Thread.Sleep(m_Random.Next(2000, 6000));
if (_ChromeDriver.WindowHandles.First() != _ChromeDriver.WindowHandles.Last())
{
_ChromeDriver.SwitchTo().Window(_ChromeDriver.WindowHandles.Last());
_ChromeDriver.Close();
_ChromeDriver.SwitchTo().Window(_ChromeDriver.WindowHandles.First());
}
}
catch (Exception ex)
{
Console.WriteLine("=== 검색어 ===");
Console.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
Console.WriteLine("=== 검색어 페어 ===");
Console.WriteLine(ex.Message);
}
}
/*
var elem = _ChromeDriver.FindElementByXPath("//*");
@@ -597,5 +564,19 @@ namespace NaverSearcher
return false;
}
}
private static void PageMoveWait(IWebDriver _IWebDriver)
{
// 페이지 이동 후 대기 및 끝 탭 설정
Thread.Sleep(m_Random.Next((int)optPageMoveWaitMin, (int)optPageMoveWaitMax));
_IWebDriver.SwitchTo().Window(_IWebDriver.WindowHandles.Last());
}
private static void SearchWait(IWebDriver _IWebDriver)
{
// 페이지 이동 후 대기 및 끝 탭 설정
Thread.Sleep(m_Random.Next((int)optSearchWaitMin, (int)optSearchWaitMax));
_IWebDriver.SwitchTo().Window(_IWebDriver.WindowHandles.Last());
}
}
}

View File

@@ -2,18 +2,24 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net45</TargetFramework>
<TargetFramework>net35</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
<PackageReference Include="ICSharpCode.SharpZipLib.dll" Version="0.85.4.369" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="92.0.4515.10700" />
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
@@ -21,6 +27,13 @@
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>

View File

@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;
namespace NaverSearcher
{
@@ -11,7 +13,21 @@ namespace NaverSearcher
[STAThread]
static void Main()
{
//SetEnvironmentVariable
FileInfo _FileInfo = new FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch\\chrome.exe");
if (_FileInfo.Exists == false)
{
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch"))
{
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch");
}
// <20><><EFBFBD>ҽ<EFBFBD> <20><><EFBFBD><EFBFBD>
File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch\\chrome.zip", Properties.Resources.chrome);
FastZip fastZip = new FastZip();
fastZip.ExtractZip(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch\\chrome.zip", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch", "");
}
string _guid = Properties.Settings.Default.GUID;
if (_guid == string.Empty || _guid == null)

View File

@@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 이 코드는 도구를 사용하여 생성되었습니다.
// 런타임 버전:4.0.30319.42000
//
// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
// 이러한 변경 내용이 손실됩니다.
// </auto-generated>
//------------------------------------------------------------------------------
namespace NaverSearcher.Properties {
using System;
/// <summary>
/// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.
/// </summary>
// 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder
// 클래스에서 자동으로 생성되었습니다.
// 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여 ResGen을
// 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NaverSearcher.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해 현재 스레드의 CurrentUICulture 속성을
/// 재정의합니다.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// System.Byte[] 형식의 지역화된 리소스를 찾습니다.
/// </summary>
internal static byte[] chrome {
get {
object obj = ResourceManager.GetObject("chrome", resourceCulture);
return ((byte[])(obj));
}
}
}
}

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="chrome" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>chrome.zip;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.