1

I'm just curious if there's a snippet for returning your IP address, for the classic "Your IP address is ___" gimmick.

Is there something out there?

Thanks.

flag

3 Answers

2

Since I don't have enough reputation to up vote, I'm going to "up vote" binky. That function above is far too much overkill for a simple need.

If you want to take it one step further, you can use a function

Public Shared Function GetUserIP() as string
     Return HttpContext.Current.Request.ServerVariables("remote_addr"))
End Function

Then you can just call your function

Response.Write(GetUserIP)

This is especially if you decide you want to pull the users IP address in multiple locations.

link|flag
Looking at the History of this question, binky edited the question WAY WAY far away from the original. The original question was how to return domain name availability... not return the users IP address. I don't think I'm willing to be apart of a website where moderators completely rewrite questions. As per the original question, why don't you look at... articles.sitepoint.com/article/… – rockinthesixstring Oct 12 at 1:22
Hi Rockinthesixstring, Thanks for the great answer and welcome to snippetgood.com! Since this site is less than two weeks old, we stocked it with some test questions from people we know - after our testing stuff out, we edited some test questions to make them better snippets. Complete rewrites aren't normal practice :) – binky Oct 12 at 2:33
I think it was actually me that editted it too haha – Code Newb Oct 12 at 14:33
1

This will return your IP.

Public Function GetExternalIP(ByVal Provider As String) As String
        Dim WebReq As HttpWebRequest = HttpWebRequest.Create(Provider)
        Dim WebRes As HttpWebResponse = WebReq.GetResponse()

        Dim ResStream As System.IO.Stream = WebRes.GetResponseStream
        Dim ResStreamReader As New StreamReader(ResStream, Encoding.UTF8)

        Dim IP As String = ResStreamReader.ReadToEnd

        ResStream.Close()
        WebRes.Close()

        Return IP
    End Function
link|flag
1

<%Response.Write(Request.ServerVariables("remote_addr"))%>
link|flag

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.