Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
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
Administrator
Titanium-Web-Proxy
Commits
1ab81865
Commit
1ab81865
authored
May 09, 2017
by
Daniel Herken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved to helper class
parent
0a40f3c0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
44 deletions
+45
-44
Network.cs
Titanium.Web.Proxy/Helpers/Network.cs
+44
-6
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+1
-38
No files found.
Titanium.Web.Proxy/Helpers/Network.cs
View file @
1ab81865
using
System.Linq
;
using
System.Linq
;
using
System.Net
;
using
System.Net
;
using
System.Net.Sockets
;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
...
@@ -38,5 +39,42 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -38,5 +39,42 @@ namespace Titanium.Web.Proxy.Helpers
// test if any host IP equals to any local IP or to localhost
// test if any host IP equals to any local IP or to localhost
return
IPAddress
.
IsLoopback
(
address
)
||
localIPs
.
Contains
(
address
);
return
IPAddress
.
IsLoopback
(
address
)
||
localIPs
.
Contains
(
address
);
}
}
internal
static
bool
IsLocalIpAddress
(
string
hostName
)
{
bool
isLocalhost
=
false
;
IPHostEntry
localhost
=
Dns
.
GetHostEntry
(
"127.0.0.1"
);
if
(
hostName
==
localhost
.
HostName
)
{
IPHostEntry
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
IPAddress
.
IsLoopback
);
}
if
(!
isLocalhost
)
{
localhost
=
Dns
.
GetHostEntry
(
Dns
.
GetHostName
());
IPAddress
ipAddress
=
null
;
if
(
IPAddress
.
TryParse
(
hostName
,
out
ipAddress
))
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
x
.
Equals
(
ipAddress
));
if
(!
isLocalhost
)
{
try
{
var
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
hostEntry
.
AddressList
.
Any
(
x
.
Equals
));
}
catch
(
SocketException
)
{
}
}
}
return
isLocalhost
;
}
}
}
}
}
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
1ab81865
...
@@ -46,7 +46,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -46,7 +46,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
TcpClient
client
;
TcpClient
client
;
Stream
stream
;
Stream
stream
;
bool
isLocalhost
=
IsLocalhost
(
remoteHostName
);
bool
isLocalhost
=
(
externalHttpsProxy
==
null
&&
externalHttpProxy
==
null
)
?
false
:
NetworkHelper
.
IsLocalIpAddress
(
remoteHostName
);
bool
useHttpsProxy
=
externalHttpsProxy
!=
null
&&
externalHttpsProxy
.
HostName
!=
remoteHostName
&&
(
externalHttpsProxy
.
BypassForLocalhost
&&
!
isLocalhost
);
bool
useHttpsProxy
=
externalHttpsProxy
!=
null
&&
externalHttpsProxy
.
HostName
!=
remoteHostName
&&
(
externalHttpsProxy
.
BypassForLocalhost
&&
!
isLocalhost
);
bool
useHttpProxy
=
externalHttpProxy
!=
null
&&
externalHttpProxy
.
HostName
!=
remoteHostName
&&
(
externalHttpProxy
.
BypassForLocalhost
&&
!
isLocalhost
);
bool
useHttpProxy
=
externalHttpProxy
!=
null
&&
externalHttpProxy
.
HostName
!=
remoteHostName
&&
(
externalHttpProxy
.
BypassForLocalhost
&&
!
isLocalhost
);
...
@@ -154,42 +154,5 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -154,42 +154,5 @@ namespace Titanium.Web.Proxy.Network.Tcp
Version
=
httpVersion
Version
=
httpVersion
};
};
}
}
private
bool
IsLocalhost
(
string
hostName
)
{
bool
isLocalhost
=
false
;
IPHostEntry
localhost
=
Dns
.
GetHostEntry
(
"127.0.0.1"
);
if
(
hostName
==
localhost
.
HostName
)
{
IPHostEntry
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
IPAddress
.
IsLoopback
);
}
if
(!
isLocalhost
)
{
localhost
=
Dns
.
GetHostEntry
(
Dns
.
GetHostName
());
IPAddress
ipAddress
=
null
;
if
(
IPAddress
.
TryParse
(
hostName
,
out
ipAddress
))
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
x
.
Equals
(
ipAddress
));
if
(!
isLocalhost
)
{
try
{
var
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
hostEntry
.
AddressList
.
Any
(
x
.
Equals
));
}
catch
(
SocketException
)
{
}
}
}
return
isLocalhost
;
}
}
}
}
}
\ No newline at end of file
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