Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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())
Reply With Quote
  #3 (permalink)  
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..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.