Solved

why i don't receive DHCPDiscover message from server using dongle and why same code give DHCPNac on wifi

Posted on 2015-01-12
3
26 Views
Last Modified: 2016-02-27
I have written a script using perl and i have tested it using two different ways: (1)Using a wifi connection (I have router which is directly connected to server and i am connected to that router). When i run my script on wifi connection, I receive DHCPOffer with IP and when i send request than i receive DHCPNack on that Request. i don't know why ? (2) Using the same code when i connect using a dongle then i even don't receive DHCPDiscover it just kind of hang for about hours and there is no any kind of message from server.

Below is all my code :

use IO::Socket::INET;
use Net::DHCP::Packet;
use Net::DHCP::Constants;
my $result='false';
my $nowtime = localtime(time);
print "\nprint $nowtime\n";
SocketCreation();
if ( $result eq 'true')
{
print "\nTRUE\n";
}
else
{
print "\nFALSE \n";
}
#########Here is the finction definition to SocketCreation ###########
+################
sub SocketCreation()
{
my $br_addr = sockaddr_in( '67', inet_aton('255.255.255.255') );
my $xid     = int( rand(0xFFFFFFFF) );
#my $chaddr  = '00189BF9C1Dp';
my $chaddr = '0016cbb7c882';

my $socket = IO::Socket::INET->new(
    Proto     => 'udp',
    Broadcast => 1,
    LocalPort => '68',
) or die "Can't create socket: $@\n";
print "\n please wait and have patience......:\n";
my $discover_packet = Net::DHCP::Packet->new(
    Xid                           => $xid,
    Chaddr                        => $chaddr,
    Flags                         => 0x8000,
    DHO_DHCP_MESSAGE_TYPE()       => DHCPDISCOVER(),
    DHO_HOST_NAME()               => 'Perrr',
    DHO_VENDOR_CLASS_IDENTIFIER() => 'perlr',
);
 print "/n just a check\n";
$socket->send( $discover_packet->serialize(), 0, $br_addr)
    or die "Error sending:$!\n";

my $buf = '';
print "/n just a check2\n";
$socket->recv( $buf, 1024) or die "recvfrom() failed:$!";
#print STDERR $socket->toString();
my $resp = new Net::DHCP::Packet($buf);
print "Details:\n" . $resp->toString();
$ip_offerto=$resp->yiaddr();
print "\n IP we got from google is : $ip_offerto\n";
$result = ($ip_offerto =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) ? "t
+rue":"false";
print $result;
# create DHCP Packet REQUEST
$request = Net::DHCP::Packet->new(
                      Xid => 0x12345678,
                      Ciaddr => $resp->yiaddr(),
                      DHO_DHCP_MESSAGE_TYPE() => DHCPREQUEST(),
                      DHO_VENDOR_CLASS_IDENTIFIER() => 'ShekharsIPRequ
+est',
                      DHO_DHCP_REQUESTED_ADDRESS() => $resp->yiaddr(),
                      );
print"\nSending REQUEST to server\n";
print $request->toString();
$socket->send($request->serialize(),0,$br_addr)
              or die "Error sending:$!\n";

print "\nWaiting for response from server\n";
$socket->recv($buf, 4096) || die("recv:$!");

print "\nGot response\n";
$resp = new Net::DHCP::Packet($buf);
print STDERR $resp->toString();
close($socket);
}

Actually could some one please give me solution for :

(1) Why it give DHPCNACK when i use WIfi (through another roter) ?
 (2) Why the same code hangs while run through dongle (USB Modem internet device)?
0
Comment
Question by:shekhar SHEKHAWAT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 62

Accepted Solution

by:
gheist earned 500 total points
ID: 40546065
DHCDISCOVER is sent by client. Server sends dhcpack etc.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
svi stops eigrp advertisement 13 84
Remote Desktop Services in AWS 4 51
snmp v2 configuration on a switch 3 62
How do I restrict certain programs? 9 78
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
David Varnum recently wrote up his impressions of PRTG, based on a presentation by my colleague Christian at Tech Field Day at VMworld in Barcelona. Thanks David, for your detailed and honest evaluation!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question