Echo packet

B

BigZero

hello,
i need to send echo packet as broadcast and store the responded ip
address ,i need to use UDP packet that is datagram Packet so any one
can help how to code this one



Thanks
Vijay
 
B

BigZero

Thanks RGB,
well that got much information,now how to code these thing that i m
not going to write code for client that os should respond me that why
i m using Snmp service ,ok the problem is with Thread i m getting the
response from different machine but the my code dies's when first
response received so all i need to write code that store the
ipaddress of up machine to db and by from db ill going to call back to
particular ip/machine for snmp request.
"Is there any way i can do this"


Thanks
Vijay
 
R

RedGrittyBrick

BigZero said:
Thanks RGB,
well that got much information,now how to code these thing that i m
not going to write code for client that os should respond me that why
i m using Snmp service ,ok the problem is with Thread i m getting the
response from different machine but the my code dies's when first
response received so all i need to write code that store the
ipaddress of up machine to db and by from db ill going to call back to
particular ip/machine for snmp request.

That sentence is too long for me to understand.

"Is there any way i can do this"

Yes.

I recommend you post an SSCCE based on the existing code that you are
having problems with.

Have you read these?
http://mindprod.com/jgloss/sscce.html
http://homepage1.nifty.com/algafield/sscce.html
 
B

BigZero

Well i do not known where to post so i m posting here only, let this
can help u to under stand.
here is my code i m using snmp4j pack,


import org.snmp4j.CommunityTarget;
import org.snmp4j.ScopedPDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.TimeTicks;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.transport.*;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.PDU;

class Test2
{

public static void main(String args[])
{
try
{
//UdpAddress targetAddress = new UdpAddress("192.168.1.154/161");
//IpAddress targetAddress = new IpAddress("192.168.1.150/161");
UdpAddress targetAddress = new UdpAddress("192.168.1.28/161");

CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(10000);
target.setVersion(SnmpConstants.version2c);

Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();

// prepare the PDU for sending

PDU command = new PDU();
command.setType(PDU.GET);
//command.setType(PDU.GETNEXT);

command.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));

// now send the PDU

ResponseEvent responseEvent = snmp.send(command, target);


System.out.println("Response : "+responseEvent);

//comment if (responseEvent != null)
//while(responseEvent != null)

// response has arrived. handle it
System.out.println("Received response from:
"+responseEvent.getPeerAddress());

PDU responsePDU=responseEvent.getResponse();
String resp=responsePDU.toString();
System.out.println("Output is :"+resp);
responseEvent = snmp.send(command, target);

if (responseEvent != null)
System.out.println("null response received...");
else
{
System.out.println("Received response from:
"+responseEvent.getPeerAddress());

responsePDU=responseEvent.getResponse();
resp=responsePDU.toString();
System.out.println("Output is :"+resp);
//snmp.send(command, target);
}

}
catch(Exception e)
{
System.out.println(e);
}
}
}

hope now it may clear u

Thanks
Vijay
 
B

BigZero

hi RGB

the above code works fine as single thread all i need this should run
in multi thread,





Thanks
Vijay
 
R

RedGrittyBrick

BigZero said:
Well i do not known where to post so i m posting here only, let this
can help u to under stand.
here is my code i m using snmp4j pack,

hope now it may clear u

That is much clearer. In your original posting (in *this* thread) you
mentioned UDP Datagrams, you said nothing about SNMP. A better subject
line might have been "Problems with SNMP using SNMP4J".

I can't help you with SNMP, particularly as there are many different
SNMP stacks.


What follows is of no use to the OP (BigZero) - but here is a simple
example in case any other google/newsreader-user read this thread
because the OP mentioned "Echo packet" "Broadcast" "UDP" "datagram":

------------------------------ 8< ------------------------------------
public class UdpPing {
// NOTE: needs extending to capture *all* reponders.

static final String BROADCAST = "255.255.255.255";

static final int ECHOPORT = 7;

public static void main(String[] args) {

try {
DatagramSocket socket = new DatagramSocket();
socket.setSoTimeout(1000); // in mSec.

// send request
byte[] buf = new byte[256];
InetAddress address;
address = InetAddress.getByName(BROADCAST);
DatagramPacket packet = new DatagramPacket(buf, buf.length,
address, ECHOPORT);
socket.send(packet);

// get response
packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);

// see who responded first
InetAddress responder = packet.getAddress();
System.out.println(responder + " responded.");

socket.close();

} catch (Exception e) {
e.printStackTrace();
}

}
}
------------------------------ 8< ------------------------------------
 
B

BigZero

ha ha ha ,Thanks man ,
this works,all i need to do run this in multi thread ill work on it ,
Thanks again,all i need ask u don't known me but u still helped me,may
ask u why?
any how thanks again



Regards
Vijay
 
R

RedGrittyBrick

BigZero said:
hi RGB

the above code works fine as single thread all i need this should run
in multi thread,

Having reviewed your posting history I am still very puzzled about your
goals and capabilities. I don't think I can help you much unless you can
fill in the details of those two things. Maybe someone better than I can
intuit what you need and jump in.


The fact you commented out a "while" loop in your SNMP4J example makes
me wonder if you want to iterate sequentially rather than use concurrent
threads.

Why do you need multiple threads? What problem do you have that multiple
threads would solve? Do you have an SSCCE that uses SNMP4J in multiple
threads? If so, what specific problem have you encountered that are you
unable to solve?

What are you really trying to achieve overall? Do you just want a list
of addresses of devices on the LAN? All devices? Just those devices that
have SNMP management enabled?
 
B

BigZero

My self Vijay Majagaonkar. Student G.I.T College,Belgaum,India

i m working on my final year project, the goal of project is to get
the information of software and hardware of client machine within
Lan,all i need to get the information of installed software and hard
ware fo client and store back to DB in server

Well i started this with "C" but they wanted this should run for Linux
and Win Boxes, so i came to "java" , as i m new to java i m still
learning, as while condition that time some kind of plan on mind came
that i m just trying to run the same thing again but later i came to
known that it sending packet ever time so it's just waste.......

"All i need to collect information of software and hardware from
client machine, for this i m using SNMP protocol "



Regards
Vijay
 
B

BigZero

Well Roedy Green
i didn't got any information on udp echo packet,on u r links



Regards
Vijay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top