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
b3a35de2
Commit
b3a35de2
authored
Sep 29, 2016
by
Jehonathan
Committed by
GitHub
Sep 29, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #126 from aricih/master
IP Helper API wrapped to associate port with process id
parents
3584b878
d12183fc
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
211 additions
and
2 deletions
+211
-2
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+3
-0
SystemProxy.cs
Titanium.Web.Proxy/Helpers/SystemProxy.cs
+1
-1
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+96
-1
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+23
-0
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+5
-0
TcpRow.cs
Titanium.Web.Proxy/Tcp/TcpRow.cs
+35
-0
TcpTable.cs
Titanium.Web.Proxy/Tcp/TcpTable.cs
+46
-0
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+2
-0
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
b3a35de2
...
...
@@ -115,6 +115,9 @@ namespace Titanium.Web.Proxy.Examples.Basic
//read response headers
var
responseHeaders
=
e
.
WebSession
.
Response
.
ResponseHeaders
;
// print out process id of current session
Console
.
WriteLine
(
$"PID:
{
e
.
WebSession
.
ProcessId
}
"
);
//if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return;
if
(
e
.
WebSession
.
Request
.
Method
==
"GET"
||
e
.
WebSession
.
Request
.
Method
==
"POST"
)
{
...
...
Titanium.Web.Proxy/Helpers/SystemProxy.cs
View file @
b3a35de2
...
...
@@ -11,7 +11,7 @@ using System.Linq;
namespace
Titanium.Web.Proxy.Helpers
{
internal
class
NativeMethods
internal
partial
class
NativeMethods
{
[
DllImport
(
"wininet.dll"
)]
internal
static
extern
bool
InternetSetOption
(
IntPtr
hInternet
,
int
dwOption
,
IntPtr
lpBuffer
,
...
...
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
b3a35de2
...
...
@@ -2,20 +2,116 @@
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Net.NetworkInformation
;
using
System.Net.Security
;
using
System.Net.Sockets
;
using
System.Runtime.InteropServices
;
using
System.Security.Authentication
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Tcp
;
namespace
Titanium.Web.Proxy.Helpers
{
internal
partial
class
NativeMethods
{
internal
const
int
AfInet
=
2
;
internal
enum
TcpTableType
{
BasicListener
,
BasicConnections
,
BasicAll
,
OwnerPidListener
,
OwnerPidConnections
,
OwnerPidAll
,
OwnerModuleListener
,
OwnerModuleConnections
,
OwnerModuleAll
,
}
/// <summary>
/// <see cref="http://msdn2.microsoft.com/en-us/library/aa366921.aspx"/>
/// </summary>
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
TcpTable
{
public
uint
length
;
public
TcpRow
row
;
}
/// <summary>
/// <see cref="http://msdn2.microsoft.com/en-us/library/aa366913.aspx"/>
/// </summary>
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
TcpRow
{
public
TcpState
state
;
public
uint
localAddr
;
public
byte
localPort1
;
public
byte
localPort2
;
public
byte
localPort3
;
public
byte
localPort4
;
public
uint
remoteAddr
;
public
byte
remotePort1
;
public
byte
remotePort2
;
public
byte
remotePort3
;
public
byte
remotePort4
;
public
int
owningPid
;
}
/// <summary>
/// <see cref="http://msdn2.microsoft.com/en-us/library/aa365928.aspx"/>
/// </summary>
[
DllImport
(
"iphlpapi.dll"
,
SetLastError
=
true
)]
internal
static
extern
uint
GetExtendedTcpTable
(
IntPtr
tcpTable
,
ref
int
size
,
bool
sort
,
int
ipVersion
,
int
tableClass
,
int
reserved
);
}
internal
class
TcpHelper
{
/// <summary>
/// Gets the extended TCP table.
/// </summary>
/// <returns>Collection of <see cref="TcpRow"/>.</returns>
internal
static
TcpTable
GetExtendedTcpTable
()
{
List
<
TcpRow
>
tcpRows
=
new
List
<
TcpRow
>();
IntPtr
tcpTable
=
IntPtr
.
Zero
;
int
tcpTableLength
=
0
;
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
false
,
NativeMethods
.
AfInet
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
!=
0
)
{
try
{
tcpTable
=
Marshal
.
AllocHGlobal
(
tcpTableLength
);
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
true
,
NativeMethods
.
AfInet
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
==
0
)
{
NativeMethods
.
TcpTable
table
=
(
NativeMethods
.
TcpTable
)
Marshal
.
PtrToStructure
(
tcpTable
,
typeof
(
NativeMethods
.
TcpTable
));
IntPtr
rowPtr
=
(
IntPtr
)((
long
)
tcpTable
+
Marshal
.
SizeOf
(
table
.
length
));
for
(
int
i
=
0
;
i
<
table
.
length
;
++
i
)
{
tcpRows
.
Add
(
new
TcpRow
((
NativeMethods
.
TcpRow
)
Marshal
.
PtrToStructure
(
rowPtr
,
typeof
(
NativeMethods
.
TcpRow
))));
rowPtr
=
(
IntPtr
)((
long
)
rowPtr
+
Marshal
.
SizeOf
(
typeof
(
NativeMethods
.
TcpRow
)));
}
}
}
finally
{
if
(
tcpTable
!=
IntPtr
.
Zero
)
{
Marshal
.
FreeHGlobal
(
tcpTable
);
}
}
}
return
new
TcpTable
(
tcpRows
);
}
/// <summary>
/// relays the input clientStream to the server at the specified host name & port with the given httpCmd & headers as prefix
...
...
@@ -103,6 +199,5 @@ namespace Titanium.Web.Proxy.Helpers
tcpConnection
.
Dispose
();
}
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
b3a35de2
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Shared
;
using
Titanium.Web.Proxy.Tcp
;
namespace
Titanium.Web.Proxy.Http
{
...
...
@@ -14,6 +17,8 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
public
class
HttpWebClient
{
private
int
processId
;
/// <summary>
/// Connection to server
/// </summary>
...
...
@@ -22,6 +27,24 @@ namespace Titanium.Web.Proxy.Http
public
Request
Request
{
get
;
set
;
}
public
Response
Response
{
get
;
set
;
}
/// <summary>
/// PID of the process that is created the current session
/// </summary>
public
int
ProcessId
{
get
{
if
(
processId
==
0
)
{
TcpRow
tcpRow
=
TcpHelper
.
GetExtendedTcpTable
().
TcpRows
.
FirstOrDefault
(
row
=>
row
.
LocalEndPoint
.
Port
==
ServerConnection
.
port
);
processId
=
tcpRow
?.
ProcessId
??
-
1
;
}
return
processId
;
}
}
/// <summary>
/// Is Https?
/// </summary>
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
b3a35de2
...
...
@@ -115,6 +115,11 @@ namespace Titanium.Web.Proxy
/// </summary>
public
SslProtocols
SupportedSslProtocols
{
get
;
set
;
}
=
SslProtocols
.
Tls
|
SslProtocols
.
Tls11
|
SslProtocols
.
Tls12
|
SslProtocols
.
Ssl3
;
/// <summary>
/// Is the proxy currently running
/// </summary>
public
bool
ProxyRunning
=>
proxyRunning
;
/// <summary>
/// Constructor
/// </summary>
...
...
Titanium.Web.Proxy/Tcp/TcpRow.cs
0 → 100644
View file @
b3a35de2
using
System.Net
;
using
Titanium.Web.Proxy.Helpers
;
namespace
Titanium.Web.Proxy.Tcp
{
/// <summary>
/// Represents a managed interface of IP Helper API TcpRow struct
/// <see cref="http://msdn2.microsoft.com/en-us/library/aa366913.aspx"/>
/// </summary>
internal
class
TcpRow
{
/// <summary>
/// Initializes a new instance of the <see cref="TcpRow"/> class.
/// </summary>
/// <param name="tcpRow">TcpRow struct.</param>
public
TcpRow
(
NativeMethods
.
TcpRow
tcpRow
)
{
ProcessId
=
tcpRow
.
owningPid
;
int
localPort
=
(
tcpRow
.
localPort1
<<
8
)
+
(
tcpRow
.
localPort2
)
+
(
tcpRow
.
localPort3
<<
24
)
+
(
tcpRow
.
localPort4
<<
16
);
long
localAddress
=
tcpRow
.
localAddr
;
LocalEndPoint
=
new
IPEndPoint
(
localAddress
,
localPort
);
}
/// <summary>
/// Gets the local end point.
/// </summary>
public
IPEndPoint
LocalEndPoint
{
get
;
private
set
;
}
/// <summary>
/// Gets the process identifier.
/// </summary>
public
int
ProcessId
{
get
;
private
set
;
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/Tcp/TcpTable.cs
0 → 100644
View file @
b3a35de2
using
System.Collections
;
using
System.Collections.Generic
;
namespace
Titanium.Web.Proxy.Tcp
{
/// <summary>
/// Represents collection of TcpRows
/// </summary>
/// <seealso cref="System.Collections.Generic.IEnumerable{Titanium.Web.Proxy.Tcp.TcpRow}" />
internal
class
TcpTable
:
IEnumerable
<
TcpRow
>
{
private
readonly
IEnumerable
<
TcpRow
>
tcpRows
;
/// <summary>
/// Initializes a new instance of the <see cref="TcpTable"/> class.
/// </summary>
/// <param name="tcpRows">TcpRow collection to initialize with.</param>
public
TcpTable
(
IEnumerable
<
TcpRow
>
tcpRows
)
{
this
.
tcpRows
=
tcpRows
;
}
/// <summary>
/// Gets the TCP rows.
/// </summary>
public
IEnumerable
<
TcpRow
>
TcpRows
=>
tcpRows
;
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>An enumerator that can be used to iterate through the collection.</returns>
public
IEnumerator
<
TcpRow
>
GetEnumerator
()
{
return
tcpRows
.
GetEnumerator
();
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.</returns>
IEnumerator
IEnumerable
.
GetEnumerator
()
{
return
GetEnumerator
();
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
b3a35de2
...
...
@@ -92,6 +92,8 @@
<Compile
Include=
"Http\Responses\OkResponse.cs"
/>
<Compile
Include=
"Http\Responses\RedirectResponse.cs"
/>
<Compile
Include=
"Shared\ProxyConstants.cs"
/>
<Compile
Include=
"Tcp\TcpRow.cs"
/>
<Compile
Include=
"Tcp\TcpTable.cs"
/>
</ItemGroup>
<ItemGroup
/>
<ItemGroup>
...
...
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