HI i want to get my own pc's ip adress and want to send to server database.how can i get this???

Dani AI

Generated

Short practical summary (for ; building on ’s suggestion): when a browser talks to your ASP.NET server the server only ever sees the address on the TCP connection (usually the client’s public IP or the last proxy/load‑balancer). Classic ASP.NET exposes that via the request object; when a proxy is involved the original client IP is usually placed in an X‑Forwarded‑For/Forwarded header. (learn.microsoft.com)

A robust, minimal server-side approach (C# / classic ASP.NET) — check X‑Forwarded‑For first, fall back to the connection IP, and trim the value you store:

string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
    // may be a comma-separated list; take the first entry
    ip = ip.Split(',')[0].Trim();
}
else
{
    ip = Request.UserHostAddress;
}

Important: X‑Forwarded‑For can be spoofed unless it’s added by a trusted proxy. In ASP.NET Core, prefer the ForwardedHeaders middleware and explicitly configure the proxies/networks you trust rather than relying on raw headers. (web.nodejs.cn)

When saving to a database: prefer a binary format when your DB supports it (MySQL: INET6_ATON -> VARBINARY(16)); if storing text, use a field that can hold full IPv6 (common guidance is VARCHAR(45) to be safe). Always normalize the value, use parameterized queries, index the column, and consider retention/anonymization for privacy. (dev.mysql.com)

If you actually need a client’s private LAN IP (192.168.x.x / 10.x.x.x) that cannot be retrieved from the server over plain HTTP — you need client-side code or a native agent. Browser-based tricks (WebRTC) used to work but modern browsers hide local addresses via mDNS for privacy, so that approach is unreliable without special browser configuration or enterprise policies. Consider whether you really need the private IP and get user consent if you store it. (getstream.io)

Troubleshooting tips: log both the raw headers and the resolved IP during testing, test behind your real proxy/load‑balancer, and watch for IPv6 vs IPv4 formatting when searching or indexing stored values.

You'll need to clarify the question a bit regarding...

i want to get my own pc's ip adress

Do you mean that you want to capture the IP address of the visitor accessing your website? If so, that's pretty simple.

Add a label, textbox or other similar control and in your code behind use the servervariables collection to access the remote IP address. For example...

lblIP.Text = Request.ServerVariables("remote_addr")

To store this in a database, you treat this like any other data that you need to save. Are you familiar with making a database connection?

Are you developing in VB or C#?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.