473,890 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ICMP packets

Hi,

I was doing a research looking for Java solutions that are able to do
"ping".

I found old messages (and not so old ones), telling that Java was not
able to do that, because the API provided do not support raw sockets.
The only solution that I found was a "simulation " of a ping program
doing a UDP request to a server on port 7.

So I decided to read the API (1.4.2) and I found that the package
"java.net" is able to send ICMP packets.

Actually, and this is my question, I only found an exception that:
"Signals that an ICMP Port Unreachable message has been received on a
connected datagram."
(http://java.sun.com/j2se/1.4.2/docs/...xception.html).

Well, if the package has a exception for ICMP, I can supose that now I
am able to talk ICMP using Java
(http://java.sun.com/j2se/1.4.2/docs/...amSocket.html).

Am I right?

And finally: does someone did something related to this, using the new
api? Is it possible to post an example?

Thanks,

Bob Rivers
Sao Paulo - Brazil
Jul 17 '05
13 24065
Matt Smith <ma********@uco nn.edu> wrote in message
Although this topic seems to have headed off in a different direction,
the ICMP exception you refer to does not infer that Java can handle ICMP
directly. For example, if your code attempts to connect to a TCP port
that does not exist on a remote server, the server will return an "ICMP
Port Unreachable" message. That is a standard TCP/UDP operation. So
Java only handles this type of operational return message.

Just wanted to give you the "FYI"

-Matt


Thanks,

Bob
Jul 17 '05 #11
bo*******@pobox .com (Bob Rivers) wrote in message news:<aa******* *************** ***@posting.goo gle.com>...
Hi,

I was doing a research looking for Java solutions that are able to do
"ping".

I found old messages (and not so old ones), telling that Java was not
able to do that, because the API provided do not support raw sockets.
The only solution that I found was a "simulation " of a ping program
doing a UDP request to a server on port 7.

So I decided to read the API (1.4.2) and I found that the package
"java.net" is able to send ICMP packets.

Actually, and this is my question, I only found an exception that:
"Signals that an ICMP Port Unreachable message has been received on a
connected datagram."
(http://java.sun.com/j2se/1.4.2/docs/...xception.html).

Well, if the package has a exception for ICMP, I can supose that now I
am able to talk ICMP using Java
(http://java.sun.com/j2se/1.4.2/docs/...amSocket.html).

Am I right?

And finally: does someone did something related to this, using the new
api? Is it possible to post an example?

Thanks,

Bob Rivers
Sao Paulo - Brazil

If you want to get really hardcore, you can dl JPcap:
http://netresearch.ics.uci.edu/kfuji...doc/links.html

Then you'll be able to control every network layer on your machine
from within Java code. Note: JPcap is not portable, so you need to dl
different versions for different OS'.

-Cory
Jul 17 '05 #12
Sam
co*******@hotma il.com (Cory) wrote in message
If you want to get really hardcore, you can dl JPcap:
http://netresearch.ics.uci.edu/kfuji...doc/links.html

Then you'll be able to control every network layer on your machine
from within Java code. Note: JPcap is not portable, so you need to dl
different versions for different OS'.

-Cory


Hi Cory,

Have you tried the ping solution there? I've given it an intial try,
but no luck - nothing gets put out to the network.

There is a comment in the source about having to set the Ethernet
header in windows, but the call to the raw socket (which is a JNI call
to winpcap) on accepts IPPacket, so it's impossible to specify
(although an EthernetPacket Java class is provided as an extension to
a DataLink class).

Sam90
Jul 17 '05 #13
Krishna
1 New Member
I have extended socket and tried connecting to a host using
Socket(address, port) constructor. If the error thrown is ConnectExceptio n it means though the server is up the connection to that port is not entertained.
If an UnknownHostExce ption is thrown this simply means that the host is down/ the route is down.

This is the simplest ping simulation i could come up with. Following is the code...


import java.io.IOExcep tion;
import java.net.*;
public class Pingo_client extends Socket{

public static void main(String[] args) {
try {
Pingo_client p1=new Pingo_client(In etAddress.getLo calHost(),2559) ;
System.out.prin tln("the remote host is UP");
p1.close();
} catch (UnknownHostExc eption e) {
System.out.prin tln("Remote host down");
} catch (IOException e) {
e.printStackTra ce();
}

}
Pingo_client(In etAddress address, int port){
try {
new Socket(address, port);
} catch (ConnectExcepti on e) {
// TODO Auto-generated catch block
System.out.prin tln("Connection refused");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTra ce();
}
}
}
Jun 16 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2609
by: Andreas Pauley | last post by:
Hi, I'd like to generate my own icmp packets from within python. Typically this would include sending an ECHO_REQUEST and checking if I get an ECHO_REPLY back. But I would also like to send/receive other icmp types, like timestamp and timestamp replies. At the moment I'm playing with the socket module: import socket
0
1645
by: T.C.McQueen | last post by:
Does anyone know how to receive an ICMP-Router Advertisement Message using Raw/ICMP - Sockets in Multicast -Mode with .NET I tried it several times differently but it does not work I think it's impossible, because I cannot receive any data with the Receive- or the ReceiveFrom-Method withou losing the multicast-membership I hope that I am wrong Please help me ! ( Maybe with code snippets :-) )
0
1592
by: billiejoex | last post by:
Hi all. The source below is a simple icmp sniffer made with pcapy. To decode packets I'm using the EthDecoder() function that returns a rapresentation of the packet including ICMP type, ICMP code, IP source and IP destination. All I need, now, is to get the ip src and ip dst only but I don't know how to do it. I tried to use the IPDecoder instead of EthDecoder to decode packets but misteriously it doesn't works. Does anybody have a good...
1
5184
by: Fotis | last post by:
hi there i have two questions 1)Is there a library class for ICMP packet creation ,management etc to use with C# 2)I have created a socket of icmp type and after sending a packet i call the socket.ReceiveFrom method.During the execution of this method i want to have a time-out value and if it exceeds the value to stop the execution i can't wait for ever untill the server responds.Is such a thing
0
7795
by: Ed | last post by:
I've attached some VB.NET code I've hacked together (some taken from MS examples & newsgroup postings) that will perform a ping or IcmpSendEcho using the icmp.dll (see this for more info: http://support.microsoft.com/default.aspx?scid=kb;en-us;170591 ). The problem I have is in order to perform a discovery/ping of an entire subnet (192.168.1.* for instance) I have to do a FOR loop to itterate through all of the addresses. That it seems...
5
1679
by: Tom Anderson | last post by:
Hi all, This is a little function to compare two iterators: def icmp(a, b): for xa in a: try: xb = b.next()
2
1937
by: linuxsrbabu | last post by:
Hi all, can any one please answer this question 1) If i ping to google.com there might be several routers in between let us say R1, R2,R3,R4 what happens when packet visits R1,R2,R3,R4 do we get reply packets from there to r from direct google.com 2) if Tracert to google what happens when the request packet visits at respective routers
13
2886
by: Banupriya06 | last post by:
Hi please coould you help me out how to capture ICMP packets from the network in a client server architecture?
0
3547
by: NeoIndigo | last post by:
Hi guys, It's my first time trying to create a packet in C++. So, what i have done so far are: 1. I have opened a packet level raw socket. Using this command: sd = socket(PF_PACKET,SOCK_RAW,ETHERTYPE_IP) ; 2. I have gotten the interface number corresponding to interface name. Using the command: ioRtnCode = ioctl(sd,SIOCGIFINDEX,&ifioctl) ; here, &ifioctl is supplied with eht1, in the ifrn_name from 0 to 4.
0
9970
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11207
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10896
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4652
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.