-
March 26th, 2005, 08:29 AM
#1
Obtaining a Connecting Client's IP Address
What I would like to know is how I can go about obtaining the IP of a client connecting to my server while trying to login. The reason for this is because I would like my server to compare the IP with acceptable IPs in an XML file.
Now I know one solution would be to make my own packets and have the client send his/her IP somewhere in a login packet, put implementing packets takes quite a lot of time and this is only a small project, experiment, w/e.
Any help will be greatly appreciated.
-
March 26th, 2005, 02:11 PM
#2
Re: Obtaining a Connecting Client's IP Address
-
March 28th, 2005, 07:26 AM
#3
Re: Obtaining a Connecting Client's IP Address
It really depends what you are using for connection.
is it sockets? ordinary HTTP? what are you using for client to connect?
If you think you CAN, you can, If you think you CAN'T, you are probably right.
Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
-
March 28th, 2005, 09:11 AM
#4
Re: Obtaining a Connecting Client's IP Address
I am using source based off of the example found here:
http://www.codeguru.com/Csharp/Cshar...cle.php/c7695/
My client connects using this function:
void Join(object sender, System.EventArgs e)
{
if(port.Text == "" || IP.Text == "")
{
MessageBox.Show("IP Address and Port Number are required to connect to the Server\n");
return;
}
try
{
m_clientSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
IPAddress ip = IPAddress.Parse (IP.Text);
int iPortNo = System.Convert.ToInt16 ( port.Text);
IPEndPoint ipEnd = new IPEndPoint (ip,iPortNo);
m_clientSocket.Connect ( ipEnd );
if(m_clientSocket.Connected)
{
WaitForData();
}
}
catch(SocketException se)
{
string str = "\nConnection failed, is the server running?\n" + se.Message;
MessageBox.Show (str);
}
}
-
March 28th, 2005, 09:45 AM
#5
Re: Obtaining a Connecting Client's IP Address
get address list from Ipendpoint.
If you think you CAN, you can, If you think you CAN'T, you are probably right.
Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
-
March 28th, 2005, 01:32 PM
#6
Re: Obtaining a Connecting Client's IP Address
care to elaborate on that?
I'm still new to C# sockets...
-
March 29th, 2005, 05:13 AM
#7
Re: Obtaining a Connecting Client's IP Address
in your server...
Socket m_ConnectedClientSocketHandler = /*Client connection*/
Console.WriteLine(IPAddress.Parse (((IPEndPoint)ConnectedClientSocketHandler .RemoteEndPoint).Address.ToString ()));
If you think you CAN, you can, If you think you CAN'T, you are probably right.
Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
-
April 1st, 2005, 08:20 AM
#8
Re: Obtaining a Connecting Client's IP Address
Originally Posted by MAL1C3
What I would like to know is how I can go about obtaining the IP of a client connecting to my server while trying to login. The reason for this is because I would like my server to compare the IP with acceptable IPs in an XML file.
Now I know one solution would be to make my own packets and have the client send his/her IP somewhere in a login packet, put implementing packets takes quite a lot of time and this is only a small project, experiment, w/e.
Any help will be greatly appreciated.
try either of this
x=Request.ServerVariables["REMOTE_ADDR"]
or
x=Request.ServerVariables["REMOTE_HOST"]
-
April 4th, 2005, 02:02 AM
#9
Re: Obtaining a Connecting Client's IP Address
suhaib, that would work perfect for a web request. but here, as i understand, he is working using Sockets and need to get the IP address of the connecting client.
thanks for you suggestion. it is nice, now I will know too
If you think you CAN, you can, If you think you CAN'T, you are probably right.
Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|