I have an a server application built in C# witch listens a tcp port an receive some data packages from clients. The problem is there are clients with dynamic ip address, so at a moment i have one client with more connections opened. I need a way to determine when the client changed his ip and close the old connection.
List<Socket> ClientsToRemove = new List<Socket>();
---this foreach this to avoid connections with the same ip address---
foreach(Socket client1 in AllConnections)
{
int count = 0;
foreach(Socket client2 in AllConnections)
{
if(((IPEndPoint)client1.RemoteEndPoint).Address.ToString() == ((IPEndPoint)client2.RemoteEndPoint).Address.ToString())
{
count++;
}
}
if(count>1)
{
AllConnections.Remove(client1);
UpdateActiveConnectionsBox(AllConnections.Count.ToString());
}
}
---verify active connections---
foreach (Socket client in AllConnections)
{
if (!client.IsConnected())
{
ClientsToRemove.Add(client);
}
else
{
UpdateLogBox("Active client IP:" + ((IPEndPoint)client.RemoteEndPoint).Address.ToString());
}
}
UpdateLogBox("ACtive connection numer: " + AllConnections.Count.ToString());
foreach (Socket client in ClientsToRemove)
if (AllConnections.Contains(client))
AllConnections.Remove(client);
ClientsToRemove.Clear();
ClientsToRemove = null;
UpdateActiveConnectionsBox(AllConnections.Count.ToString());
Thread.Sleep(1500);
And this is where i accept new connections:
ServerMainSocket.Listen(10);
Socket TempSock = ServerMainSocket.Accept();
Task.Factory.StartNew(() => { ClientFunction(TempSock); });
UpdateLogBox("New client connected from IP:" + ((IPEndPoint)TempSock.RemoteEndPoint).Address.ToString());
if(AllConnections.Contains(TempSock) != true)
{
AllConnections.Add(TempSock);
}
else
{
AllConnections.Remove(TempSock);
AllConnections.Add(TempSock);
UpdateActiveConnectionsBox(AllConnections.Count.ToString());
}
Related
I've created an DHCP server and I've added a TCP server. When I send a message at address IPv4 of the DHCP server, the client answer with: ConnectionRefused.
I've set the property to true
DataSocket = new DatagramSocket();
DataSocket.Control.MulticastOnly = true;
This code running to boot of the app UWP:
private void Start()
{
if (this.StatusButton.Content.ToString().Equals(AVVIA))
{
this.ViewModel.Action = "AVVIO DEL SERVER DHCP IN CORSO...";
RunServer();
this.StatusButton.Content = UPDATE;
Task.Run(async () =>
{
await Task.Delay(DELAY);
Server = new Server();
Server.StartServer();
});
}
... ... ...
private void RunServer()
{
IPAddress iPAddress;
DhcpServer = new ScaemDhcp.DhcpServer();
iPAddress = new IPAddress(new byte[] { 192, 168, 1, 101 });
DhcpServer.Run(iPAddress, DNS, SUB_MASK, SERVER_IDENTIFIER, ROUTER_IP);
}
public void Run(IPAddress iPAddress, string dns, string subnetMask, string serverIdentifier, string routerIP)
{
var server = new Dhcp(iPAddress);
server.ServerName = dns;
server.BroadcastAddress = IPAddress.Broadcast.ToString();
server.OnDataReceived += (sender, dhcpRequest) =>
{
try
{
var type = dhcpRequest.GetMsgType();
var ip = iPAddress;
var replyOptions = new DhcpReplyOptions();
replyOptions.SubnetMask = IPAddress.Parse(subnetMask);
replyOptions.DomainName = server.ServerName;
replyOptions.ServerIdentifier = IPAddress.Parse(serverIdentifier);
replyOptions.RouterIP = IPAddress.Parse(routerIP);
replyOptions.DomainNameServers = new IPAddress[]
{IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4")};
if (type == DhcpMsgType.DHCPDISCOVER)
{
dhcpRequest.SendDHCPReply(DhcpMsgType.DHCPOFFER, ip, replyOptions);
}
if (type == DhcpMsgType.DHCPREQUEST)
{
dhcpRequest.SendDHCPReply(DhcpMsgType.DHCPACK, ip, replyOptions);
}
}
catch (Exception e)
{ }
};
server.Start();
}
... ...
public async void StartServer()
{
try
{
var streamSocketListener = new StreamSocketListener();
streamSocketListener.ConnectionReceived += this.StreamSocketListener_ConnectionReceived;
await streamSocketListener.BindServiceNameAsync(PORT.ToString());
}
catch (Exception ex)
{
... ...
Firstly, you need to check if you have add the capability Private Networks (Client & Server), this capability provides inbound and outbound access to home and work networks through the firewall. Please refer to this document(enter link description here).
And then, you need to check if the port is available, you can add the rules for port 5037 in firewall, please try with following command.
netsh advfirewall firewall add rule name="5037 In" dir=in protocol=TCP localport=5037 action=Allow
netsh advfirewall firewall add rule name="5037 Out" dir=out protocol=TCP localport=5037 action=Allow
From comment by #Michale Xu - MSFT
#Nicolò, I have given a response on MSDN forum about the similar issue.
I need make client-server game with 2 players. I bind client sockets on localhost and different ports. For connection clients send serialized msg with enum header and theirs IPEndPoints as value. When server receives connection messages from different clients, they are having same ports. How to fix it?
Method which receives connections:
public static void GetConnections()
{
while (true)
{
Console.WriteLine("Waiting for connections...");
var len = ServerSocket.Receive(TempData);
var msg = (NetMessage)DataSerializer.Deserialize(TempData);
Console.WriteLine(msg.Data.ToString());
if (msg.PacketType == PacketType.CONNECT)
{
String[] IP = msg.Data.ToString().Split(':');
if (Player1IP == null)
{
Player1IP = new IPEndPoint(IPAddress.Parse(IP[0]), Int32.Parse(IP[1]));
Console.WriteLine("Approved connection of player 1 with remote endpoint: " + Player1IP);
}
else if (Player2IP == null)
{
Player2IP = new IPEndPoint(IPAddress.Parse(IP[0]), Int32.Parse(IP[1]));
Console.WriteLine("Approved connection of player 2 with remote endpoint: " + Player2IP);
}
if (Player1IP != null && Player2IP != null)
{
Console.WriteLine("Both player are connected");
Console.WriteLine(Player1IP + " " + Player2IP);
return;
}
}
}
Connection method(runs once):
public void GetConnection()
{
NetMessage msg = new NetMessage(PacketType.CONNECT, ClientSocket.LocalEndPoint.ToString());
var bytes = DataSerializer.Serialize(msg);
ClientSocket.SendTo(bytes, ServerIP);
BeganConnection = true;
}
I am using the latest version of pcap.net to capture network traffic on my local pc ethernet card. I am using the following code to capture all traffic associated with a specific mac address.
private void bwCapture_DoWork(object sender, DoWorkEventArgs e)
{
capture = true;
IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
if (allDevices.Count == 0)
{
MessageBox.Show("No interfaces found!");
return;
}
if (capture)
{
// Print the list
for (int i = 0; i != allDevices.Count; ++i)
{
LivePacketDevice device = allDevices[i];
this.BeginInvoke((Action)delegate () { cmbNetworkDevice.Items.Add((i + 1) + ". " + device.Name); });
}
// Take the selected adapter
PacketDevice selectedDevice = allDevices[deviceSelected];
// Open the device
using (PacketCommunicator communicator = selectedDevice.Open(65536, // portion of the packet to capture
PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
50)) // read timeout
{
this.BeginInvoke((Action)delegate () { rtbCaptured.Text = "Listening on " + selectedDevice.Description + Environment.NewLine; });
// Retrieve the packets
Packet packet;
while (capture)
{
try
{
BerkeleyPacketFilter filter = communicator.CreateFilter("ether host <<MAC ADDRESS>> and tcp port 2000");
communicator.SetFilter(filter);
PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);
switch (result)
{
case PacketCommunicatorReceiveResult.Timeout:
// Timeout elapsed
continue;
case PacketCommunicatorReceiveResult.Ok:
this.BeginInvoke((Action)delegate ()
{
IpV4Datagram ip = packet.Ethernet.IpV4;
TcpDatagram tcp = ip.Tcp;
if (tcp != null && ip != null)
{
string IPCheck = ip.Source.ToString();
int PortCheck = tcp.DestinationPort;
dgvIncomingPackets.Rows.Add(packet.Timestamp.ToString("MM-dd-yyyy hh:mm:ss"), packet.Length, tcp.SequenceNumber , ip.IpV4.Protocol, ip.Source, tcp.SourcePort, ip.Destination, tcp.DestinationPort);
rtbPacketDeconstruct.Text = WordWrap(ProcessString(packet.BytesSequenceToHexadecimalString()),47);
string convertThis = ProcessString(packet.BytesSequenceToHexadecimalString());
dgvIncomingPackets.FirstDisplayedScrollingRowIndex = dgvIncomingPackets.RowCount - 1;
}
else
{
rtbCaptured.Text += "Error : TCP Null Value" + Environment.NewLine;
}
});
break;
default:
throw new InvalidOperationException("The result " + result + " should never be reached here");
}
}
catch (Exception ex)
{
this.BeginInvoke((Action)delegate ()
{ rtbCaptured.Text += "Exception : " + ex; });
}
}
}
}
}
The code above works however it is not detecting all of the skinny events. When viewing the network traffic with WireShark I am able to see the condition changes in a Cisco 7960 IP Phone including off hook, lamp messages, displaynotification messages.
While these packets are registered in Wireshark on my PC they appear not to be captured using the code above.
My understanding is that skinny uses tcp ports 2000 and 49828 for communication between CUCM and the device. My code does see the TCP ACK and WHOAMI packets.The MAC address being monitored in the Cisco IP Phone. My PC is connected to this device through the built in hub on the device(This isn't the issue because WireShark is showing the events on my PC where my code is not)
What am I missing here. I am a novice to programming and learning on the fly here. (As such I am aware my code isn't the cleanest or well written)
Thanks,
I need to list IP addresses of all connected hosts in my LAN.
What is the simplest way to do this?
You'll have to do a ping sweep. There's a Ping class in the System.Net namespace. Example follows. Also this is only possible if your computers don't have firewalls running. If they've got a firewall enabled, there's no way to determine this information short of doing SNMP queries on your switches.
System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply rep = p.Send("192.168.1.1");
if (rep.Status == System.Net.NetworkInformation.IPStatus.Success)
{
//host is active
}
The other issue is to determine how large your network is. In most home situations, your network mask will be 24 bits. This means that its set to 255.255.255.0. If your gateway is 192.168.1.1, this means that valid addresses on your network will be 192.168.1.1 to 192.168.1.254. Here's an IP Calculator to help. You'll have to loop through each address and ping the address using the Ping class and check the PingReply.
If you're just looking for the information and aren't concerned with how you get it, you can use NMap. The command would be as follows
nmap -sP 192.168.1.0/24
EDIT:
As far as speed goes, since you're on a local network, you can cut down the timeout interval considerably as your machines shouldn't take more than 100 milliseconds to reply. You can also use SendAsync to ping them all in parallel. The following program will ping 254 address in under half a second.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Net.Sockets;
namespace ConsoleApplication1
{
class Program
{
static CountdownEvent countdown;
static int upCount = 0;
static object lockObj = new object();
const bool resolveNames = true;
static void Main(string[] args)
{
countdown = new CountdownEvent(1);
Stopwatch sw = new Stopwatch();
sw.Start();
string ipBase = "10.22.4.";
for (int i = 1; i < 255; i++)
{
string ip = ipBase + i.ToString();
Ping p = new Ping();
p.PingCompleted += new PingCompletedEventHandler(p_PingCompleted);
countdown.AddCount();
p.SendAsync(ip, 100, ip);
}
countdown.Signal();
countdown.Wait();
sw.Stop();
TimeSpan span = new TimeSpan(sw.ElapsedTicks);
Console.WriteLine("Took {0} milliseconds. {1} hosts active.", sw.ElapsedMilliseconds, upCount);
Console.ReadLine();
}
static void p_PingCompleted(object sender, PingCompletedEventArgs e)
{
string ip = (string)e.UserState;
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
if (resolveNames)
{
string name;
try
{
IPHostEntry hostEntry = Dns.GetHostEntry(ip);
name = hostEntry.HostName;
}
catch (SocketException ex)
{
name = "?";
}
Console.WriteLine("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime);
}
else
{
Console.WriteLine("{0} is up: ({1} ms)", ip, e.Reply.RoundtripTime);
}
lock(lockObj)
{
upCount++;
}
}
else if (e.Reply == null)
{
Console.WriteLine("Pinging {0} failed. (Null Reply object?)", ip);
}
countdown.Signal();
}
}
}
EDIT: After some use of it myself, I modified the program to output a count of how many IPs responded. There's a const bool that if set to true, will cause the program resolve the host names of the IPs. This significantly slows down the scan, though. (under half a second to 16 seconds) Also found that if the IP address is incorrectly specified (made a typo myself), the reply object can be null, so I handled that.
You would need to build an address range (e.g. 192.168.0.1 - 192.168.255.254) and ping each of those addresses. If a response is received, then that host is active.
Asynchronous Ping Tutorial:
http://www.geekpedia.com/tutorial234_Asynchronous-Ping-using-Csharp.html
However, some newer operating systems block ping requests (ICMP). This would need to be disabled in the firewall on each computer for you to receive a response.
You can do it all in managed code. I do it using System.DirectoryServices and System.Net. Basically I get the names of the local computers from DirectoryServices (handling domains and workgroups as I go) then get each host's IP addresses from System.Net.Dns. Here's everything packed into a handy class...
public class NetworkComputer {
private string _domain;
private string _name;
private IPAddress[] _addresses = null;
public string Domain { get { return _domain; } }
public string Name { get { return _name; } }
public IPAddress[] Addresses { get { return _addresses; } }
private NetworkComputer(string domain, string name) {
_domain = domain;
_name = name;
try { _addresses = Dns.GetHostAddresses(name); } catch { }
}
public static NetworkComputer[] GetLocalNetwork() {
var list = new List<NetworkComputer>();
using(var root = new DirectoryEntry("WinNT:")) {
foreach(var _ in root.Children.OfType<DirectoryEntry>()) {
switch(_.SchemaClassName) {
case "Computer":
list.Add(new NetworkComputer("", _.Name));
break;
case "Domain":
list.AddRange(_.Children.OfType<DirectoryEntry>().Where(__ => (__.SchemaClassName == "Computer")).Select(__ => new NetworkComputer(_.Name, __.Name)));
break;
}
}
}
return list.OrderBy(_ => _.Domain).ThenBy(_ => _.Name).ToArray();
}
}
Then just call the static method to get an array of your LAN computers...
var localComputers = NetworkComputer.GetLocalNetwork();
Nazim was correct. And krowe2's reply is factually incorrect. Switches absolutely forward broadcast traffic. You can send a ping to the subnet's broadcast address under the following conditions.
1.a) You are on the same subnet.
1.b) the gateway allows for IP direct broadcast
2.a) The subnet is not part of a fabric network.
2.b) If the subnet is part of a fabric, broadcast traffic is allowed on the subnet.
In about 80% of networks (and about 99.99% of networks using 192.168.1.1 as a gateway) this will work. I'm a network engineer and I do this all the time.
You CAN NOT rely on ICMP (ping) responses to validate the existence of a device on a network. The problem is that no device is required to listen to any traffic. Not ping, not SNMP, not NetBios. The only real way to be sure is to look at the ARP table.
You have to send out any kind of traffic to every IP in the subnet and look at your own ARP table. Because no device can get any traffic until resolve the MAC address of the IP on the local subnet. So before a device decides if it's going to listen to traffic or not, it has to respond to an ARP request. Your device then caches this in it's ARP table and can send frames with the right destination MAC to the other device.
On a Windows PC, the command line command is 'arp -a'. Linux is 'arp -n' if I recall correctly.
You could ping the adress range and note if a host responded. Of course, this will require the host to respond to the ping packets.
namespace WindowsFormsApplication1
{
class WifiInformation
{
static CountdownEvent countdown;
static int upCount = 0;
static object lockObj = new object();
const bool resolveNames = true;
static void Main(string[] args)
{
string ipBase = getIPAddress();
string[] ipParts = ipBase.Split('.');
ipBase = ipParts[0] + "." + ipParts[1] + "." + ipParts[2] + ".";
for (int i = 1; i < 255; i++)
{
string ip = ipBase + i.ToString();
Ping p = new Ping();
p.PingCompleted += new PingCompletedEventHandler(p_PingCompleted);
p.SendAsync(ip, 100, ip);
}
Console.ReadLine();
}
static void p_PingCompleted(object sender, PingCompletedEventArgs e)
{
string ip = (string)e.UserState;
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
if (resolveNames)
{
string name;
try
{
IPHostEntry hostEntry = Dns.GetHostEntry(ip);
name = hostEntry.HostName;
}
catch (SocketException ex)
{
name = "?";
}
Console.WriteLine("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime);
}
else
{
Console.WriteLine("{0} is up: ({1} ms)", ip, e.Reply.RoundtripTime);
}
lock (lockObj)
{
upCount++;
}
}
else if (e.Reply == null)
{
Console.WriteLine("Pinging {0} failed. (Null Reply object?)", ip);
}
}
public static string getIPAddress()
{
IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
}
}
return localIP;
}
}
}
Instead of arranging a wild ping-party, you could possibly (I really don't know exactly!) use NetBIOS (request the netbios nametable somehow?) http://technet.microsoft.com/en-us/library/cc757216%28WS.10%29.aspx. Or why not ask your DHCP server?
Ping to the global broadcast ip address (192.168.1.255)
Normally we will get the reply from all the host connected to the LAN.. Or if you have any particular network for the lan, ping to that networks broadcast id (i.e the last ip address in that range ).
Then you can know all the ip address connected to the host in lan.
I have two lan cards installed in my pc. One is for internet connection and another for share the internet to client machines. I am getting my IP with this code:
IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName()));
foreach (IPAddress ip in HosyEntry.AddressList)
{
trackingIp = ip.ToString();
textBox1.Text += trackingIp + ",";
}
How can I find which one my internet connecting IP (I dont want to do it by text processing)?
The best way to get this information is to use WMI, this program outputs the IP addresses for the network adapter that's registered for the network destination "0.0.0.0", which is for all intents and purposes "not my network", aka "the internet" (Note: I'm not a networking expert so that may not be entirely correct).
using System;
using System.Management;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_IP4RouteTable WHERE Destination=\"0.0.0.0\"");
int interfaceIndex = -1;
foreach (var item in searcher.Get())
{
interfaceIndex = Convert.ToInt32(item["InterfaceIndex"]);
}
searcher = new ManagementObjectSearcher("root\\CIMV2",
string.Format("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE InterfaceIndex={0}", interfaceIndex));
foreach (var item in searcher.Get())
{
var ipAddresses = (string[])item["IPAddress"];
foreach (var ipAddress in ipAddresses)
{
Console.WriteLine(ipAddress);
}
}
}
}
}
Ok. I wrote 2 methods.
First method is faster but require to use a socket.
It tries to connect to remote host using each local IP.
Second methos is slower and did not use sockets. It connects to remote host (get response, waste some traffic) and look for local IP in the active connections table.
Code is draft so double check it.
namespace ConsoleApplication1
{
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
class Program
{
public static List<IPAddress> GetInternetIPAddressUsingSocket(string internetHostName, int port)
{
// get remote host IP. Will throw SocketExeption on invalid hosts
IPHostEntry remoteHostEntry = Dns.GetHostEntry(internetHostName);
IPEndPoint remoteEndpoint = new IPEndPoint(remoteHostEntry.AddressList[0], port);
// Get all locals IP
IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
var internetIPs = new List<IPAddress>();
// try to connect using each IP
foreach (IPAddress ip in hostEntry.AddressList) {
IPEndPoint localEndpoint = new IPEndPoint(ip, 80);
bool endpointIsOK = true;
try {
using (Socket socket = new Socket(localEndpoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) {
socket.Connect(remoteEndpoint);
}
}
catch (Exception) {
endpointIsOK = false;
}
if (endpointIsOK) {
internetIPs.Add(ip); // or you can return first IP that was found as single result.
}
}
return internetIPs;
}
public static HashSet <IPAddress> GetInternetIPAddress(string internetHostName)
{
// get remote IPs
IPHostEntry remoteMachineHostEntry = Dns.GetHostEntry(internetHostName);
var internetIPs = new HashSet<IPAddress>();
// connect and search for local IP
WebRequest request = HttpWebRequest.Create("http://" + internetHostName);
using (WebResponse response = request.GetResponse()) {
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
response.Close();
foreach (TcpConnectionInformation t in connections) {
if (t.State != TcpState.Established) {
continue;
}
bool isEndpointFound = false;
foreach (IPAddress ip in remoteMachineHostEntry.AddressList) {
if (ip.Equals(t.RemoteEndPoint.Address)) {
isEndpointFound = true;
break;
}
}
if (isEndpointFound) {
internetIPs.Add(t.LocalEndPoint.Address);
}
}
}
return internetIPs;
}
static void Main(string[] args)
{
List<IPAddress> internetIP = GetInternetIPAddressUsingSocket("google.com", 80);
foreach (IPAddress ip in internetIP) {
Console.WriteLine(ip);
}
Console.WriteLine("======");
HashSet<IPAddress> internetIP2 = GetInternetIPAddress("google.com");
foreach (IPAddress ip in internetIP2) {
Console.WriteLine(ip);
}
Console.WriteLine("Press any key");
Console.ReadKey(true);
}
}
}
NICs that route to the Internet have a gateway. The benefit of this approach is that you don't have to do a DNS lookup or bounce of a web server.
Here's some code that displays local IPs for a NIC that has a valid gateway:
/// <summary>
/// This utility function displays all the IP addresses that likely route to the Internet.
/// </summary>
public static void DisplayInternetIPAddresses()
{
var sb = new StringBuilder();
// Get a list of all network interfaces (usually one per network card, dialup, and VPN connection)
var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var network in networkInterfaces)
{
// Read the IP configuration for each network
var properties = network.GetIPProperties();
// Only consider those with valid gateways
var gateways = properties.GatewayAddresses.Select(x => x.Address).Where(
x => !x.Equals(IPAddress.Any) && !x.Equals(IPAddress.None) && !x.Equals(IPAddress.Loopback) &&
!x.Equals(IPAddress.IPv6Any) && !x.Equals(IPAddress.IPv6None) && !x.Equals(IPAddress.IPv6Loopback));
if (gateways.Count() < 1)
continue;
// Each network interface may have multiple IP addresses
foreach (var address in properties.UnicastAddresses)
{
// Comment these next two lines to show IPv6 addresses too
if (address.Address.AddressFamily != AddressFamily.InterNetwork)
continue;
sb.AppendLine(address.Address + " (" + network.Name + ")");
}
}
MessageBox.Show(sb.ToString());
}
You could use http://www.whatismyip.org/ it echos back your IP.