IP Viewer [Tutorial] - Updated

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
7 posts Page 1 of 1
Contributors
User avatar
Thomas
VIP - Donator
VIP - Donator
Posts: 36
Joined: Sat Oct 01, 2011 1:51 am

IP Viewer [Tutorial] - Updated
Thomas
This is my first tutorial, i notice that a user named Code already posted this, but i cleaned up and explained his code.

Add
3 textbox's and some labels if you would like
Textbox 1 is going to display the External IP Address
Textbox 2 will display your internal ip address
and textbox 3 will show the mac address.
-The labels can go next to the textbox's to show what IP is what.

-Today we will be using some Imports so go ahead and add these 3.
Code: Select all
Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Net.NetworkInformation.NetworkInterface
-Getting the MAC Address, this is the simple step. Since we are using the networkinformation import we will have this code look through all of the network address and fish out the mac address to be displayed anywhere but we will get too that later. This code will and needs to be placed below the Public Class Form1 area.
Code: Select all
Function getMacAddress()
        Dim nics() As NetworkInterface = _
              NetworkInterface.GetAllNetworkInterfaces 'Retrieves all network address's
        Return nics(0).GetPhysicalAddress.ToString 'This will get the actual MAC address from the address pool we generated
-Getting the External IP, this is a little bit more advanced. Basically we will have our application browse to a website that display's your ip address, download that information and return and display in your application.
Code: Select all
Dim webclient As New System.Net.WebClient
        Dim ipaddress As String
        ipaddress = System.Text.Encoding.ASCII.GetString(( _
        webclient.DownloadData("http://http://whatismyip.org/")))
        TextBox1.Text = ipaddress
-Getting the Internal IP address, this will basically browse our network address's and pull out the internal ip address to be displayed in your application.
Code: Select all
Dim Ip As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName)


        For Each internalIP As Net.IPAddress In Ip.AddressList
            If internalIP.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
                TextBox2.Text = internalIP.ToString
            End If
        Next
Forgot to include this, but this is how you will display the MAC address in a textbox or label etc. Just change the textbox3 to label 3 or anything you like
Code: Select all
TextBox3.Text = getMacAddress()
Thank you for viewing my first tutorial and i hope your like it!
Last edited by Thomas on Sat Oct 01, 2011 4:49 pm, edited 1 time in total.
Image
Image
Image
Image
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: IP Viewer [Tutorial]
clanc789
Nice tut ^^
Practice makes perfect!

VIP since: 6-10-2011
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: IP Viewer [Tutorial]
comathi
Awesome... There have been a lot of these but this is much cleaner :D
User avatar
Thomas
VIP - Donator
VIP - Donator
Posts: 36
Joined: Sat Oct 01, 2011 1:51 am

Re: IP Viewer [Tutorial]
Thomas
Thank you! :)
Image
Image
Image
Image
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: IP Viewer [Tutorial]
M1z23R
Nicely explained... :) Great work...
But as i said, http://automation.whatismyip.com/n09230945.asp is not a permanent link... when it changes you'll have to change it in your app.
Use http://whatismyip.org it is easier to remember for other apps, and it is permanent ;)
User avatar
Thomas
VIP - Donator
VIP - Donator
Posts: 36
Joined: Sat Oct 01, 2011 1:51 am

Re: IP Viewer [Tutorial]
Thomas
M1z23R wrote:
Nicely explained... :) Great work...
But as i said, http://automation.whatismyip.com/n09230945.asp is not a permanent link... when it changes you'll have to change it in your app.
Use http://whatismyip.org it is easier to remember for other apps, and it is permanent ;)
Thank you for bringing this to my attention :) I have fixed it
Image
Image
Image
Image
User avatar
mrstean
VIP - Donator
VIP - Donator
Posts: 12
Joined: Sat Jun 18, 2011 4:12 pm

Re: IP Viewer [Tutorial] - Updated
mrstean
Awesome! Thanks for this tutorial.
7 posts Page 1 of 1
Return to “Tutorials”