Skip to content

Commit 9196274

Browse files
test
1 parent 19acc01 commit 9196274

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

P2PBootstrap/Program.cs

+13-5
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,19 @@ public static void Main(string[] args)
187187
{
188188
app.MapGet("/api/Bootstrap/publicip", async (HttpContext context) =>
189189
{
190-
var headers = context.Request.Headers.ToDictionary(h => h.Key, h => h.Value.ToString());
191-
return Results.Text(headers.ToString());
192-
193-
string ip = context.Connection.RemoteIpAddress?.ToString() ?? "Unknown";
194-
return Results.Text(ip, "text/plain");
190+
var forwardedFor = context.Request.Headers["X-Forwarded-For"].ToString();
191+
string clientIp = string.Empty;
192+
193+
if (!string.IsNullOrEmpty(forwardedFor))
194+
{
195+
clientIp = forwardedFor.Split(',').First().Trim();
196+
}
197+
else
198+
{
199+
clientIp = context.Connection.RemoteIpAddress?.ToString() ?? "Unknown";
200+
}
201+
string result = $"Header: X-Forwarded-For | Value: {forwardedFor} | ClientIP: {clientIp}";
202+
return Results.Text(result, "text/plain");
195203
});
196204
}
197205

0 commit comments

Comments
 (0)