Get ip address

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Get ip address

Posted 01 February 2013 - 07:43 PM

Hi, i used to get external ip address from "http://automation.whatismyip.com/n09230945.asp"

but it's no longer "free", so, anyway to get external ip address on string?
Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: Get ip address

#2 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 01 February 2013 - 09:05 PM

View PostHeBTeMy, on 01 February 2013 - 08:43 PM, said:

Hi, i used to get external ip address from "http://automation.whatismyip.com/n09230945.asp"

but it's no longer "free", so, anyway to get external ip address on string?

Well, there are a few sites that will give you your IP address, one is here.

Or, you could play around with this code.
    Private Sub GetIPAddr()
        Dim hostName As String
        Dim ipAddr() As IPAddress

        hostName = System.Net.Dns.GetHostName()
        ipAddr = Dns.GetHostAddresses(hostName)

        For i = 0 To ipAddr.Count - 1
            Debug.Print(CStr(i) & " " & ipAddr(i).ToString)
        Next
    End Sub


This gives a number of IP addresses. In my case entry 2 is my external IP address (in Hexadecimal), and entries 3 and 4 are internal (LAN) addresses (in Decimal).
Was This Post Helpful? 1
  • +
  • -

#3 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: Get ip address

Posted 01 February 2013 - 09:26 PM

Thanks, it works with that site.

Appreciated.
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1052
  • View blog
  • Posts: 4,076
  • Joined: 02-July 08

Re: Get ip address

Posted 01 February 2013 - 09:41 PM

This gives you one address - you just have to carve it out of the string given.
Using wb As New WebClient
      Dim s As String = wb.DownloadString("http://www.whatsmyip.us/showipsimple.php")
      MessageBox.Show(s)
End Using


Result = document.write("33.223.445.23")

Full script here.
Was This Post Helpful? 1
  • +
  • -

#5 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Get ip address

Posted 02 February 2013 - 07:27 PM

i believe lar3ry's code will only return the local ip. You're most likely looking for the external/public ip. I highly recommend you just hook it up to your own php script and get the ip with that.
<?php
$ipaddress = $_SERVER["REMOTE_ADDR"];
echo $ipaddress
?>



will get and return the ip address as a string. Or, if you're getting the ip address for security, make a php script for logging in and then just simply have it also record the ip address of the person logging in and their username.

But, if you're using it for something else that doesn't require it to be recorded on the server, then simply use that code with your own php file and use regex to extract it.
Was This Post Helpful? 0
  • +
  • -

#6 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 02 February 2013 - 09:18 PM

View PostLilGhost, on 02 February 2013 - 08:27 PM, said:

i believe lar3ry's code will only return the local ip.

Actually, it returns all the IP addresses associated with the hostname supplied as a string. As I mentioned, the local (LAN) IP and the external (WAN) IP are both returned.

I am interested in your script, though. I am not at all familiar with PHP, and my first question would be to ask how one invokes a PHP script, with or without VB.Net.
.

This post has been edited by lar3ry: 02 February 2013 - 09:19 PM

Was This Post Helpful? 0
  • +
  • -

#7 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Get ip address

Posted 03 February 2013 - 11:04 AM

View Postlar3ry, on 02 February 2013 - 09:18 PM, said:

View PostLilGhost, on 02 February 2013 - 08:27 PM, said:

i believe lar3ry's code will only return the local ip.

Actually, it returns all the IP addresses associated with the hostname supplied as a string. As I mentioned, the local (LAN) IP and the external (WAN) IP are both returned.

I am interested in your script, though. I am not at all familiar with PHP, and my first question would be to ask how one invokes a PHP script, with or without VB.Net.
.

I wasn't familiar with it either until about a week ago xD anyways, what i'd do is write:
Imports System.Net
Imports System.IO
Imports System.Text.RegularExpressions

Dim req As httpwebrequest = httpwebrequest.create("MyDomain.com/checkIp.php")
req.Method = "GET"

Dim response At Httpwebresponse = DirectCast(req.GetResponse(), Httpwebresponse)
Dim readBackData As String = New StreamReader(response.GetResponseStream()).ReadToEnd



Then carve it out in some regex.

This post has been edited by LilGhost: 03 February 2013 - 11:05 AM

Was This Post Helpful? 0
  • +
  • -

#8 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: Get ip address

Posted 03 February 2013 - 11:08 AM

And what's that have to do with the php function above post? Is that how it's used?
Was This Post Helpful? 0
  • +
  • -

#9 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Get ip address

Posted 03 February 2013 - 11:18 AM

View PostHeBTeMy, on 03 February 2013 - 11:08 AM, said:

And what's that have to do with the php function above post? Is that how it's used?

The php above is the code you'd store at: "MyDomain.com/checkIp.php". Then you carve out the echo'd response using regex.
Was This Post Helpful? 0
  • +
  • -

#10 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Get ip address

Posted 03 February 2013 - 11:20 AM

If you have a website, create a php file with just this in it:
<?php echo  $_SERVER["REMOTE_ADDR"]; ?>


Sample on my site: http://www.gunnerinc.com/2.php (this won't be left there long, don't want my server to get hammered) just request that file with HTTP/sockets code and you will get your external IP returned.
Was This Post Helpful? 0
  • +
  • -

#11 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Get ip address

Posted 03 February 2013 - 01:07 PM

View PostGunnerInc, on 03 February 2013 - 11:20 AM, said:

If you have a website, create a php file with just this in it:
<?php echo  $_SERVER["REMOTE_ADDR"]; ?>


Sample on my site: http://www.gunnerinc.com/2.php (this won't be left there long, don't want my server to get hammered) just request that file with HTTP/sockets code and you will get your external IP returned.

congrats on replying with exactly what i said.
Was This Post Helpful? 0
  • +
  • -

#12 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: Get ip address

Posted 03 February 2013 - 01:21 PM

Hmm, i might try that, when u said "more security" it made me think, how can i do the same for sending mails from that application? Like store my username and password there?

Could i get an example please?
Thank you.
Was This Post Helpful? 0
  • +
  • -

#13 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Get ip address

Posted 05 February 2013 - 02:13 PM

i do NOT recommend storing your own email credentials even in an obfuscated program.

I'd much rather see you just appending text to a file on your server.

On your server's php logging file you'd write:
$ipaddress = $_SERVER["REMOTE_ADDR"];
$logfile= 'accessed.txt';
$msg = $ipaddress . "\n";
$fp = fopen($logfile, 'a');
fwrite($fp, $msg);
fclose($fp);


Was This Post Helpful? 0
  • +
  • -

#14 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: Get ip address

Posted 05 February 2013 - 02:19 PM

I'm sorry, i don't understand really nothing of php, could you explain that code?
Where would my credentials be stored? In that .txt file?
I know that is not safe to store in an application, to easy to decompile, that's why i ask.

If there isn't much troble for you to explain me i would appreciate it.
Thanks.
Was This Post Helpful? 0
  • +
  • -

#15 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 24 May 2013 - 12:28 AM

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?
Dim hostName As String
Dim ipAddr() As IPAddress

hostName = System.Net.Dns.GetHostName()
ipAddr = Dns.GetHostAddresses(hostName)

' For i = 0 To ipAddr.Count - 1
'TextBox1.Text = (CStr(i) & " " & ipAddr(i).ToString)
' Next
For i = 0 To ipAddr.Count - 1
TextBox1.Text = ipAddr(i).ToString
Next



thanks
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2