Get ip address

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 11186 Views - Last Post: 30 May 2013 - 03:18 PM Rate Topic: -----

#16 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Get ip address

Posted 24 May 2013 - 05:17 AM

View Postdave_mark, on 24 May 2013 - 01:28 AM, said:

hi guys just asking..

'this code works fine but i have some questions..
Why is it it has to take a loop For i = 0 To ipAddr.Count - 1

and y is it .count - 1? what is - 1?

It's because ipAddr = Dns.GetHostAddresses(hostName) returns an array, so in order to look through the array, we need to loop in some manner. The reason we use .count -1 is that arrays srart at an index of 0, so a 3 element array will have entries in indices 0, 1 and 2, giving a .count of 3.
Was This Post Helpful? 0
  • +
  • -

#17 dave_mark  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 15-March 13

Re: Get ip address

Posted 26 May 2013 - 10:48 PM

and y is it if i dont put a for loop but i used like this???

textbox1.text = ipaddr(1).tostring

it will return the exact ipv4 address..
Was This Post Helpful? 0
  • +
  • -

#18 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Get ip address

Posted 27 May 2013 - 06:37 AM

View Postdave_mark, on 26 May 2013 - 11:48 PM, said:

and y is it if i dont put a for loop but i used like this???
textbox1.text = ipaddr(1).tostring
it will return the exact ipv4 address..

Again, ipAddr = Dns.GetHostAddresses(hostName) returns an array, so if you want to see all the ip addresses, you need to check all the entries, and a loop is the easiest way to do it. If you know which one you want, you only need to look at one, which is what ipaddr(1) does, returning the second ip address in the array. Are you unsure of what an array is?

This post has been edited by lar3ry: 27 May 2013 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

#19 dave_mark  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 15-March 13

Re: Get ip address

Posted 27 May 2013 - 07:18 PM

thanks.. it helps me a lot. .
Was This Post Helpful? 0
  • +
  • -

#20 hackersmd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-May 13

Re: Get ip address

Posted 30 May 2013 - 03:18 PM

this is my code :
Imports System.Net
Imports System.IO
Module Module1


    Public Function ShowIp() As String

        Dim uri_val As New Uri("http://ipku.hol.es/index.php")
        Dim request As HttpWebRequest = HttpWebRequest.Create(uri_val)

        request.Method = WebRequestMethods.Http.Get


        Dim resp As HttpWebResponse = request.GetResponse()
        Dim readr As New StreamReader(resp.GetResponseStream())
        Dim myip As String = readr.ReadToEnd()

        resp.Close()

        Return myip
    End Function

End Module


and this is code for ip.php
<?php
echo $_SERVER['REMOTE_ADDR'];
?>



:bigsmile:
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2