Results 1 to 10 of 10

Thread: [RESOLVED] Get client ip

  1. #1

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Resolved [RESOLVED] Get client ip

    in asp.net ( excuse please it's a duplicate thread)

    how to get the client ip
    vb.net Code:
    1. Dim Ip_TcpIp As String
    2. Ip_TcpIp = Request.UserHostAddress()

    but it is resulting me
    ::1
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  2. #2

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Get client ip

    Any body , i tried a lot versions but suspect that the code is returning the ipv6 of my own system
    ofcourse the request is also from my laptop.

    but how i could get the ipv4
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  3. #3

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Get client ip

    Any body , i tried a lot versions but suspect that the code is returning the ipv6 of my own system
    ofcourse the request is also from my laptop.

    but how i could get the ipv4
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Get client ip

    Who's IP address are you trying to get ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Get client ip

    Try this. It will get all of the IP addresses associated with your local interface.
    Code:
    Dim strHostName As String
    Dim strIPAddress As String
    
    strHostName = System.Net.Dns.GetHostName()
    
    Dim iphe As Net.IPHostEntry = System.Net.Dns.GetHostEntry(strHostName)
    
    For Each ip As Net.IPAddress In iphe.AddressList
        Debug.WriteLine(ip.ToString)
        Select Case True
            Case ip.AddressFamily = Net.Sockets.AddressFamily.InterNetwork
                Stop 'IPv4
            Case ip.AddressFamily = Net.Sockets.AddressFamily.InterNetworkV6
                Stop 'IPv6
        End Select
    Next
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Get client ip

    But what if he wants to get his public IP address ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Get client ip

    If the OP wants the public IP they will have to get a response from a site that provides the public IP, like http://checkip.dyndns.org/ and parse it. Depending on the ISP there is no guarantee that it is constant.

    It would look something like this

    Code:
            Dim myWebRequest As Net.WebRequest = Net.WebRequest.Create("http://checkip.dyndns.org/")
            Dim myWebResponse As Net.WebResponse = myWebRequest.GetResponse()
            Dim ReceiveStream As IO.Stream = myWebResponse.GetResponseStream()
            Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
            Dim readStream As New IO.StreamReader(ReceiveStream, encode)
            Dim s As String = readStream.ReadToEnd
            Debug.WriteLine(s)
            myWebResponse.Close()
    Last edited by dbasnett; Mar 12th, 2013 at 08:28 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Get client ip

    Sorry for the delay in reply
    i need the client's IP from whom i received request


    i will try the code
    thanks one & all
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Get client ip

    Tell me, what does UserHostName return ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Get client ip

    thanks niya
    ::1
    where as my system ip is 192.168.1.21
    what i decided is
    let me first connect from other system to my laptop ( i,e ) development machine
    and
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width