File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,21 @@ public static void Main(string[] args)
187
187
{
188
188
app . MapGet ( "/api/Bootstrap/publicip" , async ( HttpContext context ) =>
189
189
{
190
+ var headerInfo = context . Request . Headers . Select ( header =>
191
+ {
192
+ // Try parsing the complete header value; note that some headers (like X-Forwarded-For)
193
+ // may contain multiple comma-separated IPs, so this is a basic example.
194
+ bool parsed = IPAddress . TryParse ( header . Value . ToString ( ) , out IPAddress ip ) ;
195
+ return new
196
+ {
197
+ Header = header . Key ,
198
+ Value = header . Value . ToString ( ) ,
199
+ ParsedIP = parsed ? ip . ToString ( ) : "Not an IP"
200
+ } ;
201
+ } ) ;
202
+ return Results . Json ( headerInfo ) ;
203
+
204
+
190
205
string ip = context . Connection . RemoteIpAddress ? . ToString ( ) ?? "Unknown" ;
191
206
return Results . Text ( ip , "text/plain" ) ;
192
207
} ) ;
You can’t perform that action at this time.
0 commit comments