SlideShare a Scribd company logo
1 of 53
NETWORK PROGRAMMING
CHAPTER 2
CHANDAN GUPTA BHAGAT
https://me.chandanbhagat.com.np
CONTENT
• The InetAddress Class: Creating a new InetAddress Objects
• Getter Methods, Address Types, Testing Reachability and Object Methods
• Inet4Address and Inet6Address
• The Network Interface Class : Factory Method and Getter Method
• Some useful programs: SpamCheck, Processing WebServer Log Files
THE INETADDRESS CLASS
THE INETADDRESS CLASS
• InetAddress class represents an IP address. The java.net.InetAddress class provides
methods to get the IP of any host name for example www.javatpoint.com,
www.google.com, www.facebook.com, etc.
• An IP address is represented by 32-bit or 128-bit unsigned number. An instance of
InetAddress represents the IP address with its corresponding host name. There are
two types of addresses: Unicast and Multicast.
• Unicast is an identifier for a single interface
• Multicast is an identifier for a set of interfaces.
• Moreover, InetAddress has a cache mechanism to store successful and unsuccessful
host name resolutions.
IP ADDRESS
• An IP address helps to identify a specific resource on the network using a numerical
representation.
• Most networks combine IP with TCP (Transmission Control Protocol). It builds a
virtual bridge among the destination and the source.
• Versions of IP
• IPV4
• IPV6
IPV4
• IPv4 is the primary Internet protocol. It is the first version of IP deployed for
production in the ARAPNET in 1983. It is a widely used IP version to differentiate
devices on network using an addressing scheme. A 32-bit addressing scheme is used
to store 232 addresses that is more than 4 million addresses.
• Features of IPv4:
• It is a connectionless protocol.
• It utilizes less memory and the addresses can be remembered easily with the class based
addressing scheme.
• It also offers video conferencing and libraries.
IPV6
• IPv6 is the latest version of Internet protocol. It aims at fulfilling the need of more
internet addresses. It provides solutions for the problems present in IPv4. It provides
128-bit address space that can be used to form a network of 340 undecillion unique
IP addresses. IPv6 is also identified with a name IPng (Internet Protocol next
generation).
• Features of IPv6:
• It has a stateful and stateless both configurations.
• It provides support for quality of service (QoS).
• It has a hierarchical addressing and routing infrastructure.
TCP/IP PROTOCOL
• TCP/IP is a communication protocol model used connect devices over a network via
internet.
• TCP/IP helps in the process of addressing, transmitting, routing and receiving the
data packets over the internet.
• The two main protocols used in this communication model are:
• TCP i.e. Transmission Control Protocol. TCP provides the way to create a communication channel
across the network. It also helps in transmission of packets at sender end as well as receiver end.
• IP i.e. Internet Protocol. IP provides the address to the nodes connected on the internet. It uses a
gateway computer to check whether the IP address is correct and the message is forwarded
correctly or not.
JAVA INETADDRESS CLASS METHODS
Methods Description
public static InetAddress getByName(String host)
throws UnknownHostException
It returns the instance of InetAddress containing
LocalHost IP and name.
public static InetAddress getLocalHost() throws
UnknownHostException
It returns the instance of InetAdddress containing local
host name and address.
public String getHostName() It returns the host name of the IP address.
public String getHostAddress() It returns the IP address in string format.
EXAMPLE CODE
https://github.com/chandan-g-bhagat/network-programming > Chapter2
EXAMPLE CODE
GETTER METHODS, ADDRESS TYPES, TESTING
REACHABILITY AND OBJECT METHODS
GETTER METHODS
public String getHostName()
public String getCanonicalHostName()
public String getAddress()
public String getHostAddress()
GETTER METHODS
public String getHostName()
• This method returns a String that contains the name of the host with the IP address
represented by the object
• There is no setHostName() method which means that the package outside cannot
change the value of HostName
• It helps making this immutable and thread safe
GETTER METHODS
public String getCanoncialHostName()
• This method is kind of similar but a bit aggressive about contacting DNS.
• It calls DNS if it can and may replace the existing cached hostname
• It is particularly useful when we are starting with the dotted quad IP address rather
than hostname
EXAMPLE CODE
https://github.com/chandan-g-bhagat/network-programming > Chapter2
GETTER METHODS
public String getAddress()
• Returns the IP Address
• Returns as an array of bytes in network byte order
EXAMPLE CODE
https://github.com/chandan-g-bhagat/network-programming > Chapter2
GETTER METHODS
public String getHostAddress()
• Returns the IP Address of localhost
EXAMPLE CODE
https://github.com/chandan-g-bhagat/network-programming > Chapter2
ADDRESS TYPES
public boolean isAnyLocalAddress()
public boolean isLoopbackAddress()
public boolean isLinkLocalAddress()
public boolean isSiteLocalAddress()
public boolean isMulticasrAddress()
public boolean isMCGlobal()
public boolean isMCNodeLocal()
public boolean isMCLinkLocal()
public boolean isMCSiteLocal()
public boolean isMCOrgLocal()
ADDRESS TYPES
public boolean isAnyLocalAddress()
• Returns true if the address is a wildcard address, false otherwise
• Useful when the system has multiple network interface (e.g. Ethernet Cards, 802.11
Wifi Adapter)
• In IPV4 the wildcard address is 0.0.0.0
• In IPV6 the wildcard address is 0:0:0:0:0:0:0:0 or ::
ADDRESS TYPES
public boolean isLoopbackAddress()
• Returns true if the address is a loopback address, false otherwise
• The loopback address connects to the same machine in the IP layer without using
any physical hardware
• In IPV4 the wildcard address is 127.0.0.1
• In IPV6 the wildcard address is 0:0:0:0:0:0:0:1 or ::1
ADDRESS TYPES
public boolean isLinkLocalAddress()
• Returns true if the address is a IPV6 link-local, false otherwise
• Helps IPV6 network to self configure
• All link local address begin with the 8 bytes FE80:0000:0000:0000, next are filled
with the local address often copied from MAC address.
ADDRESS TYPES
public boolean isSiteLocalAddress()
• Returns true if the address is a IPV6 site-local, false otherwise
• Site local address are similar to the link-local address except that they may be
forwarded by routers within the site but not beyond that
• All link local address begin with the 8 bytes FEC0:0000:0000:0000, next are filled
with the local address often copied from MAC address.
ADDRESS TYPES
public boolean IsMulticastAddress()
• Returns true if the address is a multicast address, false otherwise
• Multicast broadcasts content to all the subscribed computers rather than one.
• In IPV4 multicast address all fall in the range 224.0.0.0 to 239.255.255.255
• In IPV6 they all begin with FF
ADDRESS TYPES
public boolean isMCGlobal()
• Returns true if the address is a global multicast address, false otherwise
• The global multicast address may have the subscriber around the world.
• In IPV4 all multicast address have a global scope
• In IPV6 they all begin with FF0E or FF1E depending on whether the multicast
address is a well-known permanently assigned address or a transient address
ADDRESS TYPES
public boolean isMCOrgLocal()
• Returns true if the address is an organization-wide multicast address, false
otherwise
• The organization-wide multicast address may have the subscriber within the site of
organization.
• In IPV6 they all begin with FF08 or FF18 depending on whether the multicast
address is a well-known permanently assigned address or a transient address
ADDRESS TYPES
public boolean isMCSiteLocal()
• Returns true if the address is a site-wide multicast address, false otherwise
• Packets addressed to the site-wide multicast address will only be transmitted within
their local site.
• In IPV6 they all begin with FF05 or FF15 depending on whether the multicast
address is a well-known permanently assigned address or a transient address
ADDRESS TYPES
public boolean isMCLinkLocal()
• Returns true if the address is a subnet-wide multicast address, false otherwise
• Packets addressed to the subnet-wide multicast address will only be transmitted
within their subnet.
• In IPV6 they all begin with FF02 or FF12 depending on whether the multicast
address is a well-known permanently assigned address or a transient address
ADDRESS TYPES
public boolean isMCNodeLocal()
• Returns true if the address is a interface-wide multicast address, false otherwise
• Packets addressed to the subnet-wide multicast address are not sent beyond their
network interface.
• In IPV6 they all begin with FF01 or FF11 depending on whether the multicast
address is a well-known permanently assigned address or a transient address
TESTING REACHABILITY
public Boolean isReachable(int timeout) throws IOException
public Boolean isReachable(NetworkInterface interface, int ttl, int timeout) throws
IOException
OBJECT METHODS
public boolean equals (Object o)
public int hashCode()
public String toString()
INET4ADDRESS AND INET6ADDRESS
INET4ADDRESS AND INET6ADDRESS
public final class Inet4Address extends InetAddress
public final class Inet6Address extends InetAddress
INET4ADDRESS
• This class represents an Internet Protocol version 4 (IPv4) address. Defined by RFC 790:
Assigned Numbers, RFC 1918: Address Allocation for Private Internets, and RFC 2365: Administratively
Scoped IP Multicast
• This class extends the InetAddress class and represents an IPv4 address. It provides
methods to interpret and display useful information about IP addresses.
• Methods of this class take input in 4 formats:
• d.d.d.d : Each of the given values are assigned to 4 bytes of the IP address from left to right.
• d.d.d : The last part is interpreted as a 16-bit number and assigned to the rightmost 2 bytes as
the host address. This is generally used for specifying a class-B address.
• d.d : The last part is interpreted as a 24-bit number and assigned to the rightmost 3 bytes as the
host address. This is generally used for specifying a class-A address.
• d : The given value is directly stored as a network address without any rearrangement.
INET4ADDRESS
INET6ADDRESS
• This class represents IPv6 address and extends the InetAddress class. Methods of this class provide
facility to represent and interpret IPv6 addresses.
• Methods of this class takes input in the following formats:
• x:x:x:x:x:x:x:x –This is the general form of IPv6 address where each x can be replaced with a 16 bit
hexadecimal value of the address. Note that there must be a value in place of every ‘x’ when using
this format. For example, 4B0C:0:0:0:880C:99A8:4B0:4411
• When the address contains multiple set of 8 bits as ‘0’, a special format can be used to compress the
address. In such cases ‘::’ is replaced in place of 0’s to make the address shorter. For example, the
address in previous example can be written as- 4B0C::880C:99A8:4B0:4411
• x:x:x:x:x:x:d.d.d.d –A third format is used when hybrid addressing(IPv6 + IPv4) has to be taken care of.
In such cases the first 12 bytes are used for IPv6 addressing and remaining 4 bytes are used for IPv4
addressing. For example, F334::40CB:152.16.24.142
• ::FFFF:d.d.d.d – This type of addressing is known as IPv4-mapped addressing. It is used to aid in the
deployment of IPv6 addressing. It allows the use of same structure and socket to communicate via
both IPv6 and IPv4 connected network. First 80 bits are filled with 0’s represented by ‘::’. Next 32 bits
are all ‘1’ and remaining 32 bits represent the IPv4 address. For example, ::FFFF:152.16.24.123
INET6ADDRESS
THE NETWORK INTERFACE CLASS : FACTORY
METHOD AND GETTER METHOD
NETWORK INTERFACE CLASS
• Represents a local IP address
• Can be physical or virtual interface
• Provides methods to enumerate all the local address
• Used to create the sockets, server sockets and so on.
• Used in cases when we want to specifically use a particular interface for transmitting
our packet on a system with multiple NICs.
NETWORK INTERFACE CLASS : EXAMPLE
• https://github.com/chandan-g-bhagat/network-
programming/blob/main/Chapter2/NetInterface.java
FACTORY METHODS
• public static NetworkInterface getByName(String name) throws SocketException
• public static NetworkInterface getByInetAddress(InetAddress address) throws
SocketException
• public static Enumeration getNetworkInterface() throws SocketException
GETBYNAME(STRING NAME)
• public static NetworkInterface getByName(String name) throws SocketException
• The getByName method returns the NetworkInterface object representing the
network interface with the particular name
• No interface associated with that name, it returns null.
GETBYINETADDRESS(INETADDRESS ADDRESS)
• public static
NetworkInterface
getByInetAddress(InetAddr
ess address) throws
SocketException
• The getByInetAddress
method returns a
NetworkInterface object
bound to the IP
GETNETWORKINTERFACE()
• public static Enumeration getNetworkInterface() throws SocketException
GETTER METHODS
• public Enumeration getInetAddresses()
• public String getName()
SOME USEFUL PROGRAMS
SPAM CHECK
• A number of services monitor spammers, and inform clients whether a host attempting to connect to
them is a known spammer or not. These real-time blackhole lists need to respond to queries
extremely quickly, and process a very high load. Thousands, maybe millions, of hosts query them
repeatedly to find out whether an IP address attempting a connection is or is not a known
spammer.SpamCheck
• The nature of the problem requires that the response be fast, and ideally it should be cacheable.
Furthermore, the load should be distributed across many servers, ideally ones located around the
world. Although this could conceivably be done using a web server, SOAP, UDP, a custom protocol, or
some other mechanism, this service is in fact cleverly implemented using DNS and DNS alone.
• To find out if a certain IP address is a known spammer, reverse the bytes of the address, add the
domain of the blackhole service, and look it up. If the address is found, it's a spammer. If it isn't, it's
not. For instance, if you want to ask sbl.spamhaus.org if 207.87.34.17 is a spammer, you would look
up the hostname 17.34.87.207.sbl.spamhaus.org. (Note that despite the numeric component, this is
a hostname ASCII string, not a dotted quad IP address.)
SPAM CHECK
• If the DNS query succeeds (and, more specifically, if it returns the address
127.0.0.2), then the host is known to be a spammer. If the lookup fails-that is, it
throws an UnknownHostException-it isn’t.
• If you use this technique, be careful to stay on top of changes to blackhole list
policies and addresses. For obvious reasons, blackhole servers are frequent targets
of DDOS and other attacks, so you want to be careful that if the blackhole server
changes its address or simply stops responding to any queries, you don't begin
blocking all traffic.
• Further note that different blackhole lists can follow slightly different protocols. For
example, a few lis return 127.0.0.1 for spamming IPs instead of 127.0.0.2.
PROCESSING WEB SERVER LOGFILES
• Web server logs track the hosts that access a website. By default, the log reports the
IP addresses of the sites that connect to the server. However, you can often get
more information from the names of those sites than from their IP addresses.
• Most web servers have an option to store hostnames instead of IP addresses but
this can hurt performance because the server needs to make a DNS request for each
hit. It is much more efficient to log the IP addresses and convert them to hostnames
at a later time, when the server isn't busy or even on another machine completely.
• Example: a program called Weblog that reads a web server logfile and prints each
line with IP addresses converted to hostnames.
• Most web servers have standardized on the common logfile format. A typical line in
the common logfile format looks like this:
285.160.186.76 unknown [17/Jun/2020:22:53:58 -0500]"GET /bgs/greenbg.gif HTTP
1.0 200 58
PROCESSING WEB SERVER LOGFILES
• This line indicates that a web browser at IP address 205.160.186.76 requested the
file /bg/greenbg.gif from 35 this web server at 11:53 PM (and 58 seconds) on June
17, 2020. The file was found (response code 200) and 50 bytes of data were
successfully transferred to the browser.
• The first field is the IP address or, if DNS resolution is turned on, the hostname from
which the connection was made. This is followed by a space. Therefore, for our
purposes, parsing the logfile is easy: everything before the first space is the IP
address, and everything after it does not need to be changed.
• The dotted quad format IP address is converted into a hostname using the usual
methodsof java.net.InetAddress.
THANK YOU
YOU CAN FIND THIS SLIDES IN
https://chandanbhagat.com.np/docs/network-programming/
AND CODES IN
https://github.com/chandan-g-bhagat/network-programming

More Related Content

What's hot

Ip addressing
Ip addressingIp addressing
Ip addressingsid1322
 
Unicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting NewUnicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting Newtechbed
 
M2M systems layers and designs standardizations
M2M systems layers and designs standardizationsM2M systems layers and designs standardizations
M2M systems layers and designs standardizationsFabMinds
 
Features of mobile ip
Features of mobile ipFeatures of mobile ip
Features of mobile ippriya Nithya
 
web communication protocols in IoT
web communication protocols in IoTweb communication protocols in IoT
web communication protocols in IoTFabMinds
 
IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6Adeel Rasheed
 
Subnetting Presentation
Subnetting PresentationSubnetting Presentation
Subnetting PresentationTouhidul Fahim
 
Application Layer Protocols for the IoT
Application Layer Protocols for the IoTApplication Layer Protocols for the IoT
Application Layer Protocols for the IoTDamien Magoni
 
CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)Sabahat Nowreen Shaik
 
Transport layer services
Transport layer servicesTransport layer services
Transport layer servicesMelvin Cabatuan
 

What's hot (20)

Ip addressing
Ip addressingIp addressing
Ip addressing
 
Unicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting NewUnicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting New
 
M2M systems layers and designs standardizations
M2M systems layers and designs standardizationsM2M systems layers and designs standardizations
M2M systems layers and designs standardizations
 
Features of mobile ip
Features of mobile ipFeatures of mobile ip
Features of mobile ip
 
web communication protocols in IoT
web communication protocols in IoTweb communication protocols in IoT
web communication protocols in IoT
 
IPV6 ADDRESS
IPV6 ADDRESSIPV6 ADDRESS
IPV6 ADDRESS
 
IPv6
IPv6IPv6
IPv6
 
IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6
 
IP Routing
IP RoutingIP Routing
IP Routing
 
Mk ppt chapter 5
Mk ppt chapter 5Mk ppt chapter 5
Mk ppt chapter 5
 
Subnetting Presentation
Subnetting PresentationSubnetting Presentation
Subnetting Presentation
 
Application Layer Protocols for the IoT
Application Layer Protocols for the IoTApplication Layer Protocols for the IoT
Application Layer Protocols for the IoT
 
ipv6 ppt
ipv6 pptipv6 ppt
ipv6 ppt
 
CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Ipv4 and Ipv6
Ipv4 and Ipv6Ipv4 and Ipv6
Ipv4 and Ipv6
 
Ip address and subnetting
Ip address and subnettingIp address and subnetting
Ip address and subnetting
 
IPV4 vs IPV6
IPV4 vs IPV6IPV4 vs IPV6
IPV4 vs IPV6
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Transport layer services
Transport layer servicesTransport layer services
Transport layer services
 

Similar to Unit 2 : Internet Address

4. Understanding Internet Protocol.pptx
4. Understanding Internet Protocol.pptx4. Understanding Internet Protocol.pptx
4. Understanding Internet Protocol.pptxRobertohtirolhsconce
 
Como definir un esquema de direcciones IPv6
Como definir un esquema de direcciones IPv6Como definir un esquema de direcciones IPv6
Como definir un esquema de direcciones IPv6Edgardo Scrimaglia
 
Conceptos ipv6, direccionamiento
Conceptos ipv6, direccionamientoConceptos ipv6, direccionamiento
Conceptos ipv6, direccionamientoEdgardo Scrimaglia
 
Java API: java.net.InetAddress
Java API: java.net.InetAddressJava API: java.net.InetAddress
Java API: java.net.InetAddressSayak Sarkar
 
8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptxZahouAmel1
 
A very good introduction to IPv6
A very good introduction to IPv6A very good introduction to IPv6
A very good introduction to IPv6Syed Arshad
 
IPV6 EXPLANATION BY FOROUZANN DATA COMMUNICATION
IPV6  EXPLANATION BY FOROUZANN DATA COMMUNICATIONIPV6  EXPLANATION BY FOROUZANN DATA COMMUNICATION
IPV6 EXPLANATION BY FOROUZANN DATA COMMUNICATIONgopi5692
 
Configuring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEMConfiguring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEMJohnny Jean Tigas
 
InfiniFlux IP Address Type
InfiniFlux IP Address TypeInfiniFlux IP Address Type
InfiniFlux IP Address TypeInfiniFlux
 
Module 1 networking basics-2
Module 1   networking basics-2Module 1   networking basics-2
Module 1 networking basics-2Ankit Dubey
 
07_IP_Addressing ayudaok.pdf
07_IP_Addressing ayudaok.pdf07_IP_Addressing ayudaok.pdf
07_IP_Addressing ayudaok.pdfJosue138778
 
Gohil-Network layer & Address Resolution Protocol.pptx
Gohil-Network layer & Address Resolution Protocol.pptxGohil-Network layer & Address Resolution Protocol.pptx
Gohil-Network layer & Address Resolution Protocol.pptxJuvil2
 

Similar to Unit 2 : Internet Address (20)

4. Understanding Internet Protocol.pptx
4. Understanding Internet Protocol.pptx4. Understanding Internet Protocol.pptx
4. Understanding Internet Protocol.pptx
 
MVA slides lesson 4
MVA slides lesson 4MVA slides lesson 4
MVA slides lesson 4
 
Networking
NetworkingNetworking
Networking
 
Network layer logical addressing
Network layer logical addressingNetwork layer logical addressing
Network layer logical addressing
 
Internetworking
InternetworkingInternetworking
Internetworking
 
Chapter 2 : Inet Address & Data Stream
Chapter 2 : Inet Address & Data StreamChapter 2 : Inet Address & Data Stream
Chapter 2 : Inet Address & Data Stream
 
Como definir un esquema de direcciones IPv6
Como definir un esquema de direcciones IPv6Como definir un esquema de direcciones IPv6
Como definir un esquema de direcciones IPv6
 
Conceptos ipv6, direccionamiento
Conceptos ipv6, direccionamientoConceptos ipv6, direccionamiento
Conceptos ipv6, direccionamiento
 
IPv4 and IPv6
IPv4 and IPv6IPv4 and IPv6
IPv4 and IPv6
 
Java API: java.net.InetAddress
Java API: java.net.InetAddressJava API: java.net.InetAddress
Java API: java.net.InetAddress
 
8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx
 
A very good introduction to IPv6
A very good introduction to IPv6A very good introduction to IPv6
A very good introduction to IPv6
 
IPV6 EXPLANATION BY FOROUZANN DATA COMMUNICATION
IPV6  EXPLANATION BY FOROUZANN DATA COMMUNICATIONIPV6  EXPLANATION BY FOROUZANN DATA COMMUNICATION
IPV6 EXPLANATION BY FOROUZANN DATA COMMUNICATION
 
Unit05
Unit05Unit05
Unit05
 
Configuring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEMConfiguring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEM
 
InfiniFlux IP Address Type
InfiniFlux IP Address TypeInfiniFlux IP Address Type
InfiniFlux IP Address Type
 
Module 1 networking basics-2
Module 1   networking basics-2Module 1   networking basics-2
Module 1 networking basics-2
 
07_IP_Addressing ayudaok.pdf
07_IP_Addressing ayudaok.pdf07_IP_Addressing ayudaok.pdf
07_IP_Addressing ayudaok.pdf
 
07_IP_Addressing.pdf
07_IP_Addressing.pdf07_IP_Addressing.pdf
07_IP_Addressing.pdf
 
Gohil-Network layer & Address Resolution Protocol.pptx
Gohil-Network layer & Address Resolution Protocol.pptxGohil-Network layer & Address Resolution Protocol.pptx
Gohil-Network layer & Address Resolution Protocol.pptx
 

More from Chandan Gupta Bhagat (20)

Unit 3 - URLs and URIs
Unit 3 - URLs and URIsUnit 3 - URLs and URIs
Unit 3 - URLs and URIs
 
Unit 7 : Network Security
Unit 7 : Network SecurityUnit 7 : Network Security
Unit 7 : Network Security
 
Unit 6 : Application Layer
Unit 6 : Application LayerUnit 6 : Application Layer
Unit 6 : Application Layer
 
Unit 5 : Transport Layer
Unit 5 : Transport LayerUnit 5 : Transport Layer
Unit 5 : Transport Layer
 
Unit 4 - Network Layer
Unit 4 - Network LayerUnit 4 - Network Layer
Unit 4 - Network Layer
 
Unit 3 - Data Link Layer - Part B
Unit 3 - Data Link Layer - Part BUnit 3 - Data Link Layer - Part B
Unit 3 - Data Link Layer - Part B
 
Unit 3 - Data Link Layer - Part A
Unit 3 - Data Link Layer - Part AUnit 3 - Data Link Layer - Part A
Unit 3 - Data Link Layer - Part A
 
Computer Network - Unit 2
Computer Network - Unit 2Computer Network - Unit 2
Computer Network - Unit 2
 
Computer Network - Unit 1
Computer Network - Unit 1Computer Network - Unit 1
Computer Network - Unit 1
 
ASP.NET
ASP.NETASP.NET
ASP.NET
 
Efficient Docker Image | MS Build Kathmandu
Efficient Docker Image | MS Build KathmanduEfficient Docker Image | MS Build Kathmandu
Efficient Docker Image | MS Build Kathmandu
 
Better Understanding OOP using C#
Better Understanding OOP using C#Better Understanding OOP using C#
Better Understanding OOP using C#
 
Parytak sahayatri
Parytak sahayatriParytak sahayatri
Parytak sahayatri
 
Developing windows 8 apps
Developing windows 8 appsDeveloping windows 8 apps
Developing windows 8 apps
 
Digilog
DigilogDigilog
Digilog
 
IOE assessment marks and attendance system
IOE assessment marks and attendance systemIOE assessment marks and attendance system
IOE assessment marks and attendance system
 
BLOGGING
BLOGGINGBLOGGING
BLOGGING
 
Oblique parallel projection
Oblique parallel projectionOblique parallel projection
Oblique parallel projection
 
Brainstorming session
Brainstorming sessionBrainstorming session
Brainstorming session
 
Presentation of 3rd Semester C++ Project
Presentation of 3rd Semester C++ ProjectPresentation of 3rd Semester C++ Project
Presentation of 3rd Semester C++ Project
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Unit 2 : Internet Address

  • 1. NETWORK PROGRAMMING CHAPTER 2 CHANDAN GUPTA BHAGAT https://me.chandanbhagat.com.np
  • 2. CONTENT • The InetAddress Class: Creating a new InetAddress Objects • Getter Methods, Address Types, Testing Reachability and Object Methods • Inet4Address and Inet6Address • The Network Interface Class : Factory Method and Getter Method • Some useful programs: SpamCheck, Processing WebServer Log Files
  • 4. THE INETADDRESS CLASS • InetAddress class represents an IP address. The java.net.InetAddress class provides methods to get the IP of any host name for example www.javatpoint.com, www.google.com, www.facebook.com, etc. • An IP address is represented by 32-bit or 128-bit unsigned number. An instance of InetAddress represents the IP address with its corresponding host name. There are two types of addresses: Unicast and Multicast. • Unicast is an identifier for a single interface • Multicast is an identifier for a set of interfaces. • Moreover, InetAddress has a cache mechanism to store successful and unsuccessful host name resolutions.
  • 5. IP ADDRESS • An IP address helps to identify a specific resource on the network using a numerical representation. • Most networks combine IP with TCP (Transmission Control Protocol). It builds a virtual bridge among the destination and the source. • Versions of IP • IPV4 • IPV6
  • 6. IPV4 • IPv4 is the primary Internet protocol. It is the first version of IP deployed for production in the ARAPNET in 1983. It is a widely used IP version to differentiate devices on network using an addressing scheme. A 32-bit addressing scheme is used to store 232 addresses that is more than 4 million addresses. • Features of IPv4: • It is a connectionless protocol. • It utilizes less memory and the addresses can be remembered easily with the class based addressing scheme. • It also offers video conferencing and libraries.
  • 7. IPV6 • IPv6 is the latest version of Internet protocol. It aims at fulfilling the need of more internet addresses. It provides solutions for the problems present in IPv4. It provides 128-bit address space that can be used to form a network of 340 undecillion unique IP addresses. IPv6 is also identified with a name IPng (Internet Protocol next generation). • Features of IPv6: • It has a stateful and stateless both configurations. • It provides support for quality of service (QoS). • It has a hierarchical addressing and routing infrastructure.
  • 8. TCP/IP PROTOCOL • TCP/IP is a communication protocol model used connect devices over a network via internet. • TCP/IP helps in the process of addressing, transmitting, routing and receiving the data packets over the internet. • The two main protocols used in this communication model are: • TCP i.e. Transmission Control Protocol. TCP provides the way to create a communication channel across the network. It also helps in transmission of packets at sender end as well as receiver end. • IP i.e. Internet Protocol. IP provides the address to the nodes connected on the internet. It uses a gateway computer to check whether the IP address is correct and the message is forwarded correctly or not.
  • 9. JAVA INETADDRESS CLASS METHODS Methods Description public static InetAddress getByName(String host) throws UnknownHostException It returns the instance of InetAddress containing LocalHost IP and name. public static InetAddress getLocalHost() throws UnknownHostException It returns the instance of InetAdddress containing local host name and address. public String getHostName() It returns the host name of the IP address. public String getHostAddress() It returns the IP address in string format.
  • 12. GETTER METHODS, ADDRESS TYPES, TESTING REACHABILITY AND OBJECT METHODS
  • 13. GETTER METHODS public String getHostName() public String getCanonicalHostName() public String getAddress() public String getHostAddress()
  • 14. GETTER METHODS public String getHostName() • This method returns a String that contains the name of the host with the IP address represented by the object • There is no setHostName() method which means that the package outside cannot change the value of HostName • It helps making this immutable and thread safe
  • 15. GETTER METHODS public String getCanoncialHostName() • This method is kind of similar but a bit aggressive about contacting DNS. • It calls DNS if it can and may replace the existing cached hostname • It is particularly useful when we are starting with the dotted quad IP address rather than hostname
  • 17. GETTER METHODS public String getAddress() • Returns the IP Address • Returns as an array of bytes in network byte order
  • 19. GETTER METHODS public String getHostAddress() • Returns the IP Address of localhost
  • 21. ADDRESS TYPES public boolean isAnyLocalAddress() public boolean isLoopbackAddress() public boolean isLinkLocalAddress() public boolean isSiteLocalAddress() public boolean isMulticasrAddress() public boolean isMCGlobal() public boolean isMCNodeLocal() public boolean isMCLinkLocal() public boolean isMCSiteLocal() public boolean isMCOrgLocal()
  • 22. ADDRESS TYPES public boolean isAnyLocalAddress() • Returns true if the address is a wildcard address, false otherwise • Useful when the system has multiple network interface (e.g. Ethernet Cards, 802.11 Wifi Adapter) • In IPV4 the wildcard address is 0.0.0.0 • In IPV6 the wildcard address is 0:0:0:0:0:0:0:0 or ::
  • 23. ADDRESS TYPES public boolean isLoopbackAddress() • Returns true if the address is a loopback address, false otherwise • The loopback address connects to the same machine in the IP layer without using any physical hardware • In IPV4 the wildcard address is 127.0.0.1 • In IPV6 the wildcard address is 0:0:0:0:0:0:0:1 or ::1
  • 24. ADDRESS TYPES public boolean isLinkLocalAddress() • Returns true if the address is a IPV6 link-local, false otherwise • Helps IPV6 network to self configure • All link local address begin with the 8 bytes FE80:0000:0000:0000, next are filled with the local address often copied from MAC address.
  • 25. ADDRESS TYPES public boolean isSiteLocalAddress() • Returns true if the address is a IPV6 site-local, false otherwise • Site local address are similar to the link-local address except that they may be forwarded by routers within the site but not beyond that • All link local address begin with the 8 bytes FEC0:0000:0000:0000, next are filled with the local address often copied from MAC address.
  • 26. ADDRESS TYPES public boolean IsMulticastAddress() • Returns true if the address is a multicast address, false otherwise • Multicast broadcasts content to all the subscribed computers rather than one. • In IPV4 multicast address all fall in the range 224.0.0.0 to 239.255.255.255 • In IPV6 they all begin with FF
  • 27. ADDRESS TYPES public boolean isMCGlobal() • Returns true if the address is a global multicast address, false otherwise • The global multicast address may have the subscriber around the world. • In IPV4 all multicast address have a global scope • In IPV6 they all begin with FF0E or FF1E depending on whether the multicast address is a well-known permanently assigned address or a transient address
  • 28. ADDRESS TYPES public boolean isMCOrgLocal() • Returns true if the address is an organization-wide multicast address, false otherwise • The organization-wide multicast address may have the subscriber within the site of organization. • In IPV6 they all begin with FF08 or FF18 depending on whether the multicast address is a well-known permanently assigned address or a transient address
  • 29. ADDRESS TYPES public boolean isMCSiteLocal() • Returns true if the address is a site-wide multicast address, false otherwise • Packets addressed to the site-wide multicast address will only be transmitted within their local site. • In IPV6 they all begin with FF05 or FF15 depending on whether the multicast address is a well-known permanently assigned address or a transient address
  • 30. ADDRESS TYPES public boolean isMCLinkLocal() • Returns true if the address is a subnet-wide multicast address, false otherwise • Packets addressed to the subnet-wide multicast address will only be transmitted within their subnet. • In IPV6 they all begin with FF02 or FF12 depending on whether the multicast address is a well-known permanently assigned address or a transient address
  • 31. ADDRESS TYPES public boolean isMCNodeLocal() • Returns true if the address is a interface-wide multicast address, false otherwise • Packets addressed to the subnet-wide multicast address are not sent beyond their network interface. • In IPV6 they all begin with FF01 or FF11 depending on whether the multicast address is a well-known permanently assigned address or a transient address
  • 32. TESTING REACHABILITY public Boolean isReachable(int timeout) throws IOException public Boolean isReachable(NetworkInterface interface, int ttl, int timeout) throws IOException
  • 33. OBJECT METHODS public boolean equals (Object o) public int hashCode() public String toString()
  • 35. INET4ADDRESS AND INET6ADDRESS public final class Inet4Address extends InetAddress public final class Inet6Address extends InetAddress
  • 36. INET4ADDRESS • This class represents an Internet Protocol version 4 (IPv4) address. Defined by RFC 790: Assigned Numbers, RFC 1918: Address Allocation for Private Internets, and RFC 2365: Administratively Scoped IP Multicast • This class extends the InetAddress class and represents an IPv4 address. It provides methods to interpret and display useful information about IP addresses. • Methods of this class take input in 4 formats: • d.d.d.d : Each of the given values are assigned to 4 bytes of the IP address from left to right. • d.d.d : The last part is interpreted as a 16-bit number and assigned to the rightmost 2 bytes as the host address. This is generally used for specifying a class-B address. • d.d : The last part is interpreted as a 24-bit number and assigned to the rightmost 3 bytes as the host address. This is generally used for specifying a class-A address. • d : The given value is directly stored as a network address without any rearrangement.
  • 38. INET6ADDRESS • This class represents IPv6 address and extends the InetAddress class. Methods of this class provide facility to represent and interpret IPv6 addresses. • Methods of this class takes input in the following formats: • x:x:x:x:x:x:x:x –This is the general form of IPv6 address where each x can be replaced with a 16 bit hexadecimal value of the address. Note that there must be a value in place of every ‘x’ when using this format. For example, 4B0C:0:0:0:880C:99A8:4B0:4411 • When the address contains multiple set of 8 bits as ‘0’, a special format can be used to compress the address. In such cases ‘::’ is replaced in place of 0’s to make the address shorter. For example, the address in previous example can be written as- 4B0C::880C:99A8:4B0:4411 • x:x:x:x:x:x:d.d.d.d –A third format is used when hybrid addressing(IPv6 + IPv4) has to be taken care of. In such cases the first 12 bytes are used for IPv6 addressing and remaining 4 bytes are used for IPv4 addressing. For example, F334::40CB:152.16.24.142 • ::FFFF:d.d.d.d – This type of addressing is known as IPv4-mapped addressing. It is used to aid in the deployment of IPv6 addressing. It allows the use of same structure and socket to communicate via both IPv6 and IPv4 connected network. First 80 bits are filled with 0’s represented by ‘::’. Next 32 bits are all ‘1’ and remaining 32 bits represent the IPv4 address. For example, ::FFFF:152.16.24.123
  • 40. THE NETWORK INTERFACE CLASS : FACTORY METHOD AND GETTER METHOD
  • 41. NETWORK INTERFACE CLASS • Represents a local IP address • Can be physical or virtual interface • Provides methods to enumerate all the local address • Used to create the sockets, server sockets and so on. • Used in cases when we want to specifically use a particular interface for transmitting our packet on a system with multiple NICs.
  • 42. NETWORK INTERFACE CLASS : EXAMPLE • https://github.com/chandan-g-bhagat/network- programming/blob/main/Chapter2/NetInterface.java
  • 43. FACTORY METHODS • public static NetworkInterface getByName(String name) throws SocketException • public static NetworkInterface getByInetAddress(InetAddress address) throws SocketException • public static Enumeration getNetworkInterface() throws SocketException
  • 44. GETBYNAME(STRING NAME) • public static NetworkInterface getByName(String name) throws SocketException • The getByName method returns the NetworkInterface object representing the network interface with the particular name • No interface associated with that name, it returns null.
  • 45. GETBYINETADDRESS(INETADDRESS ADDRESS) • public static NetworkInterface getByInetAddress(InetAddr ess address) throws SocketException • The getByInetAddress method returns a NetworkInterface object bound to the IP
  • 46. GETNETWORKINTERFACE() • public static Enumeration getNetworkInterface() throws SocketException
  • 47. GETTER METHODS • public Enumeration getInetAddresses() • public String getName()
  • 49. SPAM CHECK • A number of services monitor spammers, and inform clients whether a host attempting to connect to them is a known spammer or not. These real-time blackhole lists need to respond to queries extremely quickly, and process a very high load. Thousands, maybe millions, of hosts query them repeatedly to find out whether an IP address attempting a connection is or is not a known spammer.SpamCheck • The nature of the problem requires that the response be fast, and ideally it should be cacheable. Furthermore, the load should be distributed across many servers, ideally ones located around the world. Although this could conceivably be done using a web server, SOAP, UDP, a custom protocol, or some other mechanism, this service is in fact cleverly implemented using DNS and DNS alone. • To find out if a certain IP address is a known spammer, reverse the bytes of the address, add the domain of the blackhole service, and look it up. If the address is found, it's a spammer. If it isn't, it's not. For instance, if you want to ask sbl.spamhaus.org if 207.87.34.17 is a spammer, you would look up the hostname 17.34.87.207.sbl.spamhaus.org. (Note that despite the numeric component, this is a hostname ASCII string, not a dotted quad IP address.)
  • 50. SPAM CHECK • If the DNS query succeeds (and, more specifically, if it returns the address 127.0.0.2), then the host is known to be a spammer. If the lookup fails-that is, it throws an UnknownHostException-it isn’t. • If you use this technique, be careful to stay on top of changes to blackhole list policies and addresses. For obvious reasons, blackhole servers are frequent targets of DDOS and other attacks, so you want to be careful that if the blackhole server changes its address or simply stops responding to any queries, you don't begin blocking all traffic. • Further note that different blackhole lists can follow slightly different protocols. For example, a few lis return 127.0.0.1 for spamming IPs instead of 127.0.0.2.
  • 51. PROCESSING WEB SERVER LOGFILES • Web server logs track the hosts that access a website. By default, the log reports the IP addresses of the sites that connect to the server. However, you can often get more information from the names of those sites than from their IP addresses. • Most web servers have an option to store hostnames instead of IP addresses but this can hurt performance because the server needs to make a DNS request for each hit. It is much more efficient to log the IP addresses and convert them to hostnames at a later time, when the server isn't busy or even on another machine completely. • Example: a program called Weblog that reads a web server logfile and prints each line with IP addresses converted to hostnames. • Most web servers have standardized on the common logfile format. A typical line in the common logfile format looks like this: 285.160.186.76 unknown [17/Jun/2020:22:53:58 -0500]"GET /bgs/greenbg.gif HTTP 1.0 200 58
  • 52. PROCESSING WEB SERVER LOGFILES • This line indicates that a web browser at IP address 205.160.186.76 requested the file /bg/greenbg.gif from 35 this web server at 11:53 PM (and 58 seconds) on June 17, 2020. The file was found (response code 200) and 50 bytes of data were successfully transferred to the browser. • The first field is the IP address or, if DNS resolution is turned on, the hostname from which the connection was made. This is followed by a space. Therefore, for our purposes, parsing the logfile is easy: everything before the first space is the IP address, and everything after it does not need to be changed. • The dotted quad format IP address is converted into a hostname using the usual methodsof java.net.InetAddress.
  • 53. THANK YOU YOU CAN FIND THIS SLIDES IN https://chandanbhagat.com.np/docs/network-programming/ AND CODES IN https://github.com/chandan-g-bhagat/network-programming

Editor's Notes

  1. Like DHCP but without using the server
  2. Like DHCP but without using the server
  3. Like DHCP but without using the server
  4. Like DHCP but without using the server
  5. Like DHCP but without using the server
  6. Like DHCP but without using the server
  7. Like DHCP but without using the server
  8. Like DHCP but without using the server