Introduction



Home Screen :

Name of Experiment : Mobile IP

Exp No : MC11

Background : Student should have basic knowledge of C#.

Summary : Mobile IP (or IP mobility) is a standard communications protocol that is designed to allow mobile device users to move from one network to another while maintaining a permanent IP address. It allows location independent routing of IP datagram on the Internet. So that each mobile node is identified by its home address disregarding its current location in the Internet.

Learning Objective : Student should able to learn the concept of Mobile IP address, by performing this experiment. He/she will get the Mobile IP of their own device by running this experiment on the physical device.

Target

Target Platform : This experiment is tested on Windows Phone Emulator and Nokia Lumia 800.

Procedure

SourceCode

Source Code : Comments :
IpAddress.xaml
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ExperimentTitle" Text="Exp No. WP11" TextAlignment="Right" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="ApplicationTitle" Text="Mobile Computing" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Mobile IP" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="Get IP" Height="72" Click="button1_Click_1" HorizontalAlignment="Left" Margin="55,136,0,0" Name="button1" VerticalAlignment="Top" Width="324" />
<TextBlock Height="56" HorizontalAlignment="Left" Margin="12,243,0,0" Name="textBlock1" Text="my IP" FontSize="28" VerticalAlignment="Top" Width="99" />
<TextBlock Height="77" HorizontalAlignment="Left" Margin="117,243,0,0" Name="textBlock2" Text=" " FontSize="28" FontWeight="ExtraBold" VerticalAlignment="Top" Width="319" />
</Grid>
</Grid>










 Exp No MC11(Experiment title)



 Mobile Computing(Application title)

 Mobile IP(Page Title)



IpAddress.xaml.cs
using System.Windows;
using Microsoft.Phone.Controls;

namespace MobileIP
{
public partial class IpAddress : PhoneApplicationPage
{
public IpAddress()
{
InitializeComponent();
}
// Get IP button event
private void button1_Click_1(object sender, RoutedEventArgs e)
{
// Creation of MyIPAddress object
MyIPAddress finder = new MyIPAddress();
finder.Find((address) =>
{
Dispatcher.BeginInvoke(() =>
{
textBlock2.Text = address == null ? "Unknown" : address.ToString();
});
});
}
}
}

IpAddress.xaml.cs
using System;
using System.Net;
using System.Diagnostics;
using System.Text;
using System.Net.Sockets;

namespace MobileIP
{
public class MyIPAddress
{


Action<IPAddress> FoundCallback;
UdpAnySourceMulticastClient MulticastSocket;
const int PortNumber = 50000; // pick a number, any number
string MulticastMessage = "FIND-MY-IP-PLEASE" + new Random().Next().ToString();

public void Find(Action callback)
{
FoundCallback = callback;

MulticastSocket = new UdpAnySourceMulticastClient(IPAddress.Parse("239.255.255.250"), PortNumber);
MulticastSocket.BeginJoinGroup((result) =>
{
try
{
MulticastSocket.EndJoinGroup(result);
GroupJoined(result);
}
catch (Exception ex)
{
Debug.WriteLine("EndjoinGroup exception {0}", ex.Message);
// This can happen eg when wifi is off
FoundCallback(null);
}
},
null);
}

void callback_send(IAsyncResult result)
{
}

byte[] MulticastData;
bool keepsearching;

void GroupJoined(IAsyncResult result)
{
MulticastData = Encoding.UTF8.GetBytes(MulticastMessage);
keepsearching = true;
MulticastSocket.BeginSendToGroup(MulticastData, 0, MulticastData.Length, callback_send, null);

while (keepsearching)
{
try
{
byte[] buffer = new byte[MulticastData.Length];
MulticastSocket.BeginReceiveFromGroup(buffer, 0, buffer.Length, DoneReceiveFromGroup, buffer);
}
catch (Exception ex)
{
Debug.WriteLine("Stopped Group read due to " + ex.Message);
keepsearching = false;
}
}
}

void DoneReceiveFromGroup(IAsyncResult result)
{
IPEndPoint where;
int responselength = MulticastSocket.EndReceiveFromGroup(result, out where);
byte[] buffer = result.AsyncState as byte[];
if (responselength == MulticastData.Length )
{
Debug.WriteLine("FOUND myself at " + where.Address.ToString());
keepsearching = false;
FoundCallback(where.Address);
}
}
}
}


Snapshots


Observation

Observation : After running this experiment, developer observed that Mobile IP can also contribute to the internet security as it has a static IP address.

Video Link

For Windows Phone

Download

Right Click Here And Select Save Target For Entire Download :

Mobile IP - Experiment