Commit 28e678ac authored by JoyJ's avatar JoyJ

Initial commit

parents
{
"Version": 1,
"ProjectMap": {
"95e2bb59-d3ae-4c63-9bfe-9bd690247a36": {
"ProjectGuid": "95e2bb59-d3ae-4c63-9bfe-9bd690247a36",
"DisplayName": "SrvRecordLookup",
"ColorIndex": 0
}
},
"NextColorIndex": 1
}
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SrvRecordLookup", "SrvRecordLookup\SrvRecordLookup.csproj", "{95E2BB59-D3AE-4C63-9BFE-9BD690247A36}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95E2BB59-D3AE-4C63-9BFE-9BD690247A36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95E2BB59-D3AE-4C63-9BFE-9BD690247A36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95E2BB59-D3AE-4C63-9BFE-9BD690247A36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95E2BB59-D3AE-4C63-9BFE-9BD690247A36}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EC3884DD-FFDE-4E31-AD92-04AEFF3FFE74}
EndGlobalSection
EndGlobal
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Collections.Generic;
class Program
{
public static void Main(string[] args)
{
var tuple = GetSrvInfoForYgopro("duels.link");
string host = tuple.Item1;
int port = tuple.Item2;
Console.WriteLine($"{host},{port}");
Console.ReadKey();
}
public static (string,int) GetSrvInfoForYgopro(string host)
{
host = $"_ygopro._tcp.{host}";
string dnsServer = "114.114.114.114";
int dnsPort = 53;
byte[] req = CreateRequestData(host);
byte[]? res = null;
UdpClient udp = new UdpClient(dnsServer, dnsPort);
#if DEBUG
Console.WriteLine("Request string:");
Console.WriteLine(BitConverter.ToString(req));
#endif
udp.Send(req, req.Length);
IPEndPoint? ep = null;
res = udp.Receive(ref ep);
#if DEBUG
Console.WriteLine("Respond string:");
Console.WriteLine(BitConverter.ToString(res));
for (int index = 0; index < res.Length; index++)
{
Console.WriteLine($"{index} {(char)(res[index])} {(int)res[index]}");
}
#endif
int resPort = res[req.Length + 16] * 256 + res[req.Length + 17];
int start = req.Length + 18;
int nextLen = res[start];
string resHost = "";
while (nextLen > 0)
{
int now = 0;
for (; now < nextLen; now++)
{
resHost += (char)res[start + now + 1];
}
resHost += ".";
start = start + now + 1;
nextLen = res[start];
}
resHost = resHost.Substring(0, resHost.Length - 1);
return (resHost,resPort);
}
private static byte[] CreateRequestData(string qName)
{
//参考资料: https://datatracker.ietf.org/doc/html/rfc2782 RFC2782
MemoryStream ms = new MemoryStream();
WriteBytes(0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0);
string[] buffs = qName.Split('.');
foreach (string s in buffs)
{
byte[] b = Encoding.UTF8.GetBytes(s);
ms.WriteByte((byte)b.Length);
ms.Write(b, 0, b.Length);
}
WriteBytes(0, 0, 33, 0, 1); //srv lookup:33
return ms.ToArray();
void WriteBytes(params byte[] bytes)
{
for(int i=0;i<bytes.Length; i++)
{
ms.WriteByte(bytes[i]);
}
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"SrvRecordLookup/1.0.0": {
"runtime": {
"SrvRecordLookup.dll": {}
}
}
}
},
"libraries": {
"SrvRecordLookup/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}
\ No newline at end of file
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"SrvRecordLookup/1.0.0": {
"runtime": {
"SrvRecordLookup.dll": {}
}
}
}
},
"libraries": {
"SrvRecordLookup/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}
\ No newline at end of file
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("SrvRecordLookup")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("SrvRecordLookup")]
[assembly: System.Reflection.AssemblyTitleAttribute("SrvRecordLookup")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = SrvRecordLookup
build_property.ProjectDir = D:\VSProjects\SrvRecordLookup\SrvRecordLookup\
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.csproj.AssemblyReference.cache
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.GeneratedMSBuildEditorConfig.editorconfig
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.AssemblyInfoInputs.cache
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.AssemblyInfo.cs
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.csproj.CoreCompileInputs.cache
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Debug\net6.0\SrvRecordLookup.exe
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Debug\net6.0\SrvRecordLookup.deps.json
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Debug\net6.0\SrvRecordLookup.runtimeconfig.json
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Debug\net6.0\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Debug\net6.0\ref\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Debug\net6.0\SrvRecordLookup.pdb
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\ref\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.pdb
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Debug\net6.0\SrvRecordLookup.genruntimeconfig.cache
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("SrvRecordLookup")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("SrvRecordLookup")]
[assembly: System.Reflection.AssemblyTitleAttribute("SrvRecordLookup")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = SrvRecordLookup
build_property.ProjectDir = D:\VSProjects\SrvRecordLookup\SrvRecordLookup\
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Release\net6.0\SrvRecordLookup.exe
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Release\net6.0\SrvRecordLookup.deps.json
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Release\net6.0\SrvRecordLookup.runtimeconfig.json
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Release\net6.0\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Release\net6.0\ref\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\bin\Release\net6.0\SrvRecordLookup.pdb
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\SrvRecordLookup.GeneratedMSBuildEditorConfig.editorconfig
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\SrvRecordLookup.AssemblyInfoInputs.cache
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\SrvRecordLookup.AssemblyInfo.cs
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\SrvRecordLookup.csproj.CoreCompileInputs.cache
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\ref\SrvRecordLookup.dll
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\SrvRecordLookup.pdb
D:\VSProjects\SrvRecordLookup\SrvRecordLookup\obj\Release\net6.0\SrvRecordLookup.genruntimeconfig.cache
{
"format": 1,
"restore": {
"D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\SrvRecordLookup.csproj": {}
},
"projects": {
"D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\SrvRecordLookup.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\SrvRecordLookup.csproj",
"projectName": "SrvRecordLookup",
"projectPath": "D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\SrvRecordLookup.csproj",
"packagesPath": "C:\\Users\\31635\\.nuget\\packages\\",
"outputPath": "D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"D:\\Soft\\VS2022_Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\31635\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.101\\RuntimeIdentifierGraph.json"
}
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\31635\.nuget\packages\;D:\Soft\VS2022_Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.0.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\31635\.nuget\packages\" />
<SourceRoot Include="D:\Soft\VS2022_Shared\NuGetPackages\" />
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
\ No newline at end of file
{
"version": 3,
"targets": {
"net6.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net6.0": []
},
"packageFolders": {
"C:\\Users\\31635\\.nuget\\packages\\": {},
"D:\\Soft\\VS2022_Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\SrvRecordLookup.csproj",
"projectName": "SrvRecordLookup",
"projectPath": "D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\SrvRecordLookup.csproj",
"packagesPath": "C:\\Users\\31635\\.nuget\\packages\\",
"outputPath": "D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"D:\\Soft\\VS2022_Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\31635\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.101\\RuntimeIdentifierGraph.json"
}
}
}
}
\ No newline at end of file
{
"version": 2,
"dgSpecHash": "teRfVJKh9qv4cmVMbTUo+AGptzfeLFxb2fyNUi0sJxZ8KAU2EPfwz3PWf7SKnIiYaMjrqH0Oo+ePL763xtyIZg==",
"success": true,
"projectFilePath": "D:\\VSProjects\\SrvRecordLookup\\SrvRecordLookup\\SrvRecordLookup.csproj",
"expectedPackageFiles": [],
"logs": []
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment