Solved

ASP.Net Comparing String IP address with Request.UserHostAddress.ToString()

Posted on 2008-10-02
6
1,520 Views
Last Modified: 2012-05-05
I'm trying to compare the user IP address with the one in text format like "192.168.1.1".

Request.UserHostAddress.ToString () return string like "fe80::5161:9f74:13bd:960d%9". Definitely those two strings are not same.

How can I compare those two strings (IPs)? I've tried with NameValueCollection. But I dont' know how to make it work.

Could I please get some suggestions? Thank in advance...
0
Comment
Question by:winmyan
6 Comments
 
LVL 2

Expert Comment

by:Kimpzor
ID: 22632477
Try this
Request.ServerVariables["REMOTE_ADDR"].ToString();
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 22632491
try
HttpContext.Current.Request.UserHostAddress.ToString();
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

and also try
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

then compare which code gives you the correct format of IP address.

I IP still comes in different format than let me know.
0
 

Author Comment

by:winmyan
ID: 22635052
Thank both of you for the comments,

I've tested all.

Request.ServerVariables["REMOTE_ADDR"].ToString();
HttpContext.Current.Request.UserHostAddress.ToString();
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];  // Come out nothing

They all came out "fe80::5161:9f74:13bd:960d%9" instead of "192.168.1.1". Any hope?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 22

Expert Comment

by:prairiedog
ID: 22635084
Are you using Windows Vista?
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 22635327
It seems that you are using either Windows Vista or Windows Server 2008, in which IPv6 is intalled and enabled by default. So when you run the above code, IPv6 address will be returned instead of IPv4 address. Here is an article that will help you to convert an IPv6 address to an IPv4 address: http://aspnet.4guysfromrolla.com/articles/071807-1.aspx
0
 

Author Closing Comment

by:winmyan
ID: 31502571
Yes, I'm using Windows Vista. It works fine in production environment, because we all use IPV4.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now