Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
SrvRecordLookup
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JoyJ
SrvRecordLookup
Commits
187d1e80
Commit
187d1e80
authored
Sep 23, 2022
by
JoyJ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some comments
parent
96fc75ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
SrvRecordLookup/Program.cs
SrvRecordLookup/Program.cs
+13
-2
No files found.
SrvRecordLookup/Program.cs
View file @
187d1e80
...
...
@@ -16,10 +16,14 @@ class Program
}
public
static
(
string
,
int
)
GetSrvInfoForYgopro
(
string
host
)
{
//添加ygopro前缀
host
=
$"_ygopro._tcp.
{
host
}
"
;
//DNS服务器
string
dnsServer
=
"114.114.114.114"
;
//DNS服务器端口
int
dnsPort
=
53
;
//发送的数据
byte
[]
req
=
CreateRequestData
(
host
);
byte
[]?
res
=
null
;
...
...
@@ -28,7 +32,9 @@ class Program
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
...
...
@@ -39,8 +45,12 @@ class Program
Console
.
WriteLine
(
$"
{
index
}
{(
char
)(
res
[
index
])}
{(
int
)
res
[
index
]}
"
);
}
#endif
//返回的数据头很长,与发送的数据长度相同。
//数据头之后,第16字节~17字节为2字节的端口号。
int
resPort
=
res
[
req
.
Length
+
16
]
*
256
+
res
[
req
.
Length
+
17
];
//第18字节开始,是
//1字节的short,表示下一段host字符串的长度 -> 一段host的string -> 1字节的short,表示下一段host字符串的长度 -> 一段host的string……
//直到长度==0为止
int
start
=
req
.
Length
+
18
;
int
nextLen
=
res
[
start
];
string
resHost
=
""
;
...
...
@@ -56,14 +66,15 @@ class Program
nextLen
=
res
[
start
];
}
resHost
=
resHost
.
Substring
(
0
,
resHost
.
Length
-
1
);
//拼接host
return
(
resHost
,
resPort
);
}
private
static
byte
[]
CreateRequestData
(
string
qName
)
{
//参考资料: https://datatracker.ietf.org/doc/html/rfc2782 RFC2782
MemoryStream
ms
=
new
MemoryStream
();
//参考资料: https://datatracker.ietf.org/doc/html/rfc2782 RFC2782
WriteBytes
(
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
0
,
0
);
string
[]
buffs
=
qName
.
Split
(
'.'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment