forked from apaprocki/node-dhcpjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-client.js
53 lines (48 loc) · 1.72 KB
/
example-client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2014 Andrew Paprocki
var dhcpjs = require('dhcpjs');
var util = require('util');
var client = new dhcpjs.Client();
client.on('message', function(pkt) {
console.log('message:', util.inspect(pkt, false, 3));
});
client.on('dhcpOffer', function(pkt) {
console.log('dhcpOffer:', util.inspect(pkt, false, 3));
});
client.on('dhcpAck', function(pkt) {
console.log('dhcpAck:', util.inspect(pkt, false, 3));
});
client.on('dhcpNak', function(pkt) {
console.log('dhcpNak:', util.inspect(pkt, false, 3));
});
client.on('listening', function(addr) {
console.log('listening on', addr);
});
client.bind('0.0.0.0', 68, function() {
console.log('bound to 0.0.0.0:68');
});
// Configure a DHCPDISCOVER packet:
// xid 0x01 Transaction ID. This is a counter that the DHCP
// client should maintain and increment every time
// a packet is broadcast.
//
// chaddr Ethernet address of the interface being configured.
//
// options Object containing keys that map to DHCP options.
//
// dhcpMessageType Option indicating a DHCP protocol message (as
// opposed to a plain BOOTP protocol message).
//
// clientIdentifier Option indicating a client-configured unique name
// to be used to disambiguate the lease on the server.
var pkt = {
xid: 0x01,
chaddr: '00:01:02:03:04:05',
options: {
dhcpMessageType: dhcpjs.Protocol.DHCPMessageType.DHCPDISCOVER,
clientIdentifier: 'MyMachine',
}
}
var discover = client.createDiscoverPacket(pkt);
client.broadcastPacket(discover, undefined, function() {
console.log('dhcpDiscover: sent');
});