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
b168f3fa
Commit
b168f3fa
authored
Jul 26, 2023
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 扩展 Misc.StringConverter.ToIPEndPoint 支持转换异常时,使用默认值.
parent
8593d013
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
4 deletions
+75
-4
StringConverter.cs
Project.FLY.Misc/MISC/StringConverter.cs
+75
-4
No files found.
Project.FLY.Misc/MISC/StringConverter.cs
View file @
b168f3fa
...
...
@@ -125,14 +125,16 @@ namespace Misc
}
catch
{
try
{
try
{
IPAddress
[]
ips
=
System
.
Net
.
Dns
.
GetHostEntry
(
s
[
0
]).
AddressList
;
if
(
ips
.
Length
==
1
)
ip
=
ips
[
0
];
else
ip
=
IPAddress
.
Parse
(
"127.0.0.1"
);
}
catch
{
catch
{
return
null
;
}
}
...
...
@@ -141,6 +143,75 @@ 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