i'm using VB.NET 2003 Application program. i need to get External IP Address (internet). i searched internet and found come codes and tried that...
i tried this code... but it returned my internal IP Address...
Code:Dim IPHost As IPHostEntry = Dns.GetHostByName(Dns.GetHostName()) MessageBox.Show("My IP address is " & IPHost.AddressList(0).ToString())
and i tried this code too...
but its always returns (m.fail) instead of (m.Success). so i'm not able to get External Ip address.Code:Imports System Imports System.Text Imports System.Text.RegularExpressions Public Sub GetExternalIP() Dim whatIsMyIp As String = "http://whatismyip.com" Dim getIpRegex As String = "(?<=<TITLE>.*)\d*\.\d*\.\d*\.\d*(?=</TITLE>)" Dim wc As WebClient = New WebClient Dim utf8 As UTF8Encoding = New UTF8Encoding Dim requestHtml As String = "" Dim externalIp As IPAddress = Nothing requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp)) Dim r As Regex = New Regex(getIpRegex) Dim m As Match = r.Match(requestHtml) If (m.Success) Then externalIp = IPAddress.Parse(m.Value) MessageBox.Show(externalIp.ToString) End If End Sub
using command window - Immediate, i get values for "r" and "m". and m.success = false...
i don't have fire wall setup in my machine. and i have internet access too...? r
{System.Text.RegularExpressions.Regex}
Options: None
RightToLeft: False
? r.Match(requestHtml)
{System.Text.RegularExpressions.Match}
Captures: {System.Text.RegularExpressions.CaptureCollection}
Empty: {System.Text.RegularExpressions.Match}
Groups: {System.Text.RegularExpressions.GroupCollection}
Index: 0
Length: 0
Success: False
Value: ""
anything wrong in that code.. or anything i'm missing... if anyone have any idea how to find out the External Ip Address, please help me. if you can provide an example, then it will be a great help for me.
Thanks in advance.




Reply With Quote