Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
cad8537e
Commit
cad8537e
authored
May 17, 2025
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 字符串转 IPEndPoint 的默认值版本
parent
f503cd7b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
StringConverter.cs
Project.FLY.Misc/MISC/StringConverter.cs
+67
-0
No files found.
Project.FLY.Misc/MISC/StringConverter.cs
View file @
cad8537e
...
...
@@ -141,6 +141,73 @@ namespace Misc
return
null
;
}
// 摘要:
// 将主机名或 IP 地址解析为 IPEndPoint 实例。
public
static
IPEndPoint
ToIPEndPoint
(
string
hostNameOrAddress
,
IPAddress
default_address
,
int
default_port
)
{
IPAddress
ip
=
default_address
;
int
port
=
default_port
;
if
(
string
.
IsNullOrEmpty
(
hostNameOrAddress
))
{
return
new
IPEndPoint
(
ip
,
port
);
}
string
[]
s
=
hostNameOrAddress
.
Split
(
new
char
[]
{
':'
},
StringSplitOptions
.
RemoveEmptyEntries
);
if
(
s
.
Length
==
1
)
{
try
{
ip
=
IPAddress
.
Parse
(
s
[
0
]);
}
catch
{
try
{
IPAddress
[]
ips
=
System
.
Net
.
Dns
.
GetHostEntry
(
s
[
0
]).
AddressList
;
if
(
ips
.
Length
==
1
)
ip
=
ips
[
0
];
}
catch
{
}
}
}
else
if
(
s
.
Length
==
2
)
{
try
{
port
=
int
.
Parse
(
s
[
1
]);
}
catch
{
}
try
{
ip
=
IPAddress
.
Parse
(
s
[
0
]);
}
catch
{
try
{
IPAddress
[]
ips
=
System
.
Net
.
Dns
.
GetHostEntry
(
s
[
0
]).
AddressList
;
if
(
ips
.
Length
==
1
)
ip
=
ips
[
0
];
}
catch
{
}
}
}
return
new
IPEndPoint
(
ip
,
port
);
}
public
static
string
IPEndPoint2DirectoryName
(
IPEndPoint
ipep
)
{
return
ipep
.
Address
.
ToString
()
+
"_"
+
ipep
.
Port
.
ToString
();
...
...
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