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
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.
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
-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.
Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Net.NetworkInformation.NetworkInterface
Code: Select all
-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.
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
Code: Select all
-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.
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
Code: Select all
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
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
Code: Select all
Thank you for viewing my first tutorial and i hope your like it!TextBox3.Text = getMacAddress()
Last edited by Thomas on Sat Oct 01, 2011 4:49 pm, edited 1 time in total.
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 ;)
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 ;)
M1z23R wrote:Nicely explained... Great work...Thank you for bringing this to my attention I have fixed it
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 ;)
7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023