Results 1 to 9 of 9

Thread: Finding IP details

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Location
    Cornwall, UK
    Posts
    6

    Finding IP details

    Hi all,

    I'm trying to write a small app that finds the local machine's IP address (and SNM, DefGW, 1st DNS server, etc) then displays this nicely.

    I don't want to go down the route of doing a Shell "ipconfig /all > somefile" then reading it in as I *know* this can be done another way.

    I'm using VB 2008 Express Edition.

    Any suggestions?

    Cheers.
    Grant.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Finding IP details

    Have a look at System.Net.NetworkInformation namespace. Do a search on this forum for examples...
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: Finding IP details


  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Finding IP details

    look at my signature.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Location
    Cornwall, UK
    Posts
    6

    Re: Finding IP details

    Quote Originally Posted by Bulldog
    Code:
    Dim IpAddr() As Net.IPAddress = GetHostEntry(GetHostName()).AddressList
    For i As Integer = 0 To IpAddr.Length - 1
        MessageBox.Show(IpAddr(i).ToString)
    Next
    I put this in my Form_Load and all that happens, even before trying to run it, is that GetHostEntry(GetHostName part gets underlined in blue with the errors "GetHostEntry" and "GetHostName" not declared.

    I'm guessing it's something to do with the missing "Using Imports System.Net.dns at the top of your file" part, but I don't know where to put the "Using Imports System.Net.dns" statement.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Location
    Cornwall, UK
    Posts
    6

    Re: Finding IP details

    Quote Originally Posted by dbasnett
    look at my signature.
    I'm guessing you're referring to the the link that goes here? If so, where ought I to be putting this code and how can I use it?

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Finding IP details

    You put it at the very top of the file you are using it in.

    Ie.

    System.Net.dns

    Public Form MyForm

    However, you can add an imports at the project level so all objects can access it. See Project->Properties->References tab.

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Location
    Cornwall, UK
    Posts
    6

    Re: Finding IP details

    Quote Originally Posted by Grimfort
    You put it at the very top of the file you are using it in.

    Ie.

    System.Net.dns

    Public Form MyForm

    However, you can add an imports at the project level so all objects can access it. See Project->Properties->References tab.
    Thank you! That's helped enormously. How would I get things like the Subnet Mask, Default Gateway & DNS? I'm playing around with the code now, but not getting anywhere fast.

    Next issue... this works on XP nicely... Vista, however, comes up with a security policy warning:
    Application attempted to perform an operation not allowed by the security policy. To grant this application the required permission, contact your system administrator, or use the Microsoft .NET Framework Configuration Tool.

    If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.

    Request for the permission of type 'System.Net.DnsPermission. System.Version=2.0.0.0, Culture=neutral, PublicKey Token=b77a5c561934e089' failed.
    Last edited by Thymox; Feb 27th, 2009 at 06:42 AM.

  9. #9
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Finding IP details

    With Vista you have to run VS with admin rights, even if you are an admin. Right-click the vs icon, run as administrator.

    However, this may not be the issue, it could be that you are trying to run the application from a network share to test it, .Net apps have to be given permission to do this, just copy it locally if this is the case.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width