Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
| Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2008, 12:23 PM
Authorized User
Points: 386, Level: 6
Points: 386, Level: 6 Points: 386, Level: 6 Points: 386, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: windsor, toronto, Canada.
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default find External IP Address in VB.NET

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...
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
but its always returns (m.fail) instead of (m.Success). so i'm not able to get External Ip address.

using command window - Immediate, i get values for "r" and "m". and m.success = false...
Quote:
quote:
? 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: ""
i don't have fire wall setup in my machine. and i have internet access too...

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.
 
Old December 5th, 2008, 01:27 PM
Authorized User
Points: 386, Level: 6
Points: 386, Level: 6 Points: 386, Level: 6 Points: 386, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: windsor, toronto, Canada.
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried this code and it's working....

Code:
Dim req As HttpWebRequest = WebRequest.Create("http://whatismyip.com/automation/n09230945.asp")
        Dim res As HttpWebResponse = req.GetResponse()
        Dim Stream As Stream = res.GetResponseStream()
        Dim sr As StreamReader = New StreamReader(Stream)
        messagebox.show(sr.ReadToEnd())
 
Old March 4th, 2014, 12:31 AM
mak mak is offline
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by remya1000 View Post
I tried this code and it's working....

Code:
Dim req As HttpWebRequest = WebRequest.Create("http://whatismyip.com/automation/n09230945.asp")
        Dim res As HttpWebResponse = req.GetResponse()
        Dim Stream As Stream = res.GetResponseStream()
        Dim sr As StreamReader = New StreamReader(Stream)
        messagebox.show(sr.ReadToEnd())
nice one..




Similar Threads
Thread Thread Starter Forum Replies Last Post
get external IP Address angelboy C# 2005 8 March 29th, 2008 05:42 PM
Find IP Address for .vbs file ticktack VB How-To 1 July 27th, 2007 12:58 PM
listen on a port to a specific IP address vb.net nmmeenaa General .NET 0 September 4th, 2006 01:16 AM
Retreiving IP address & gateway address sjangit VBScript 0 February 3rd, 2004 02:02 PM
Create a find and a find and replace in VB.NET snowy0 VB How-To 0 January 26th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.