Click here to Skip to main content
12,348,594 members (40,561 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# IP Hacking Address
How to write my own firewall to detect the infiltrator ip . It is not a web application .

How to make application like Wireshark or Ethereal

How to Detect IP address in console/windows application in c# ?

Doing it in Web site is easy but i am not getting how to detect the ip of incoming packet / request in the Console/ windows application.

How to get the ip of an unknown machine if it is saving some file on my machine in a console / Windows application
Posted 14-Sep-12 1:19am
Edited 7-Oct-12 20:17pm
v8
Comments
Bernhard Hiller 17-Sep-12 4:44am
   
It is very unclear what you want to do.
What's that console/Windows application? Is that something you want to write and use as a monitor for such accesses?
Or is the issue something totally different. E.g. someone accesses your machine's hard disk, e.g. by writing to a shared directory, and you want to see that access somehow? Like the Network tab on Windows 7's Resource Monitor?
Member 8476555 17-Sep-12 5:04am
   
want to find ip address of a machine saving a file on my pc
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try this code:
using System.Net;
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
foreach(IPAddress address in localIPs)
   MessageBox.Show(address.ToString());
  Permalink  
Comments
@amitgajjar 14-Sep-12 9:08am
   
5+
Member 8476555 16-Sep-12 23:37pm
   
Doing it in Web site is easy but i am not getting how to detect the ip of incoming packet / request in the Console/ windows application.
Ekta Mehta 6-Jan-15 5:36am
   
please tell me which namespace need to write before use ipendpoint and IPaddress because i get error in name space missing... :(
JF2015 6-Jan-15 5:40am
   
As I already wrote: The "System.Net" namespace must be used.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

1.1 Framework:
StringBuilder sb = new StringBuilder();
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
    sb.Append(addr[i].ToString());
}
string myip = sb.ToString();

2.0 or later framework
StringBuilder sb = new StringBuilder();
// Get the hostname
string myHost = System.Net.Dns.GetHostName();
System.Net.IPHostEntry myIPs = System.Net.Dns.GetHostEntry(myHost);
foreach(System.Net.IPAddress myIP in myIPs.AddressList)
sb.Append(myIP.ToString());
 
string myip = sb.ToString();
  Permalink  
v2
Comments
Member 8476555 16-Sep-12 23:37pm
   
Doing it in Web site is easy but i am not getting how to detect the ip of incoming packet / request in the Console/ windows application.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

hi dear

try below code

public void getLocalIPAddress()
{
   try
   {
     string sHostName = Dns.GetHostName();
     IPHostEntry ipE = Dns.GetHostByName(sHostName);
     IPAddress[] IpA = ipE.AddressList;
     for (int i = 0; i < IpA.Length; i++)
     {
         Console.WriteLine("IP Address {0}: {1} ", i, IpA[i].ToString());
     }
   }
   catch (Exception ex)
   {
      MessageBox.Show(ex.Message.ToString(), "getLocalIPAddress");
   }
}
  Permalink  
Comments
Member 8476555 16-Sep-12 23:38pm
   
Doing it in Web site is easy but i am not getting how to detect the ip of incoming packet / request in the Console/ windows application.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

You would have to write your own firewall to do this. You would also need to write a filter driver to insert into the network stack so you can pick out all the inbound traffic and get the addresses you're interested in.

Oh, and you'll probably need to write some heuristics into your "filter" so you can get a better idea of what is and is not "unknown".

Good Luck!
  Permalink  
Comments
Member 8476555 8-Oct-12 0:36am
   
How to write your own firewall ?
Dave Kreskowiak 8-Oct-12 8:06am
   
That would take an entire book to discuss. That's FAR more information than you're going to get in a couple of forum posts.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Unareshraju 14-Sep-12 7:25am
   
http://www.aspdotnet-suresh.com/2012/07/how-to-get-find-ip-address-of-client.html
Kuthuparakkal 14-Sep-12 7:35am
   
ASP.Net solution link for Windows Form Application related question!!!
Unareshraju 14-Sep-12 8:32am
   
we don't get built in answer for every question , we need to change and develop the code .........
Member 8476555 16-Sep-12 23:38pm
   
Doing it in Web site is easy but i am not getting how to detect the ip of incoming packet / request in the Console/ windows application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100