B4J Question DHCP Server and Checking to see if MAC address is active

Peter Lewis

Active Member
Licensed User
Longtime User
Hi,
Is there any way of creating a DHCP server with B4j ?

and if there a better way of getting the IP adresses which are alive on your subnet. I am using ARP but it is not reliable

B4X:
Dim sh1 As Shell
    sh1.Initialize("sh1","arp",Array("-d"))
    sh1.Run(1000)
   
   
Dim sh1 As Shell
    sh1.Initialize("sh1","arp",Array("-a"))
    sh1.Run(2000)
    Log("alive")

then I have to use

B4X:
Sub sh1_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Dim caplet As String
    caplet=su.UpperCase(StdOut)
    File.WriteString(File.DirApp, "1.txt", caplet)
    Dim List1 As List
    List1 = File.ReadList(File.DirApp, "1.txt")
    
    For i = 2 To List1.Size - 1
        
        If su.ContainsSeq(List1.Get(i),"192.168.10") And su.ContainsSeq(List1.Get(i),"DYNAMIC") Then
            Dim ipaddress As String = su.Substring(List1.Get(i),2,16)
            Dim MACAddress As String = su.Substring(List1.Get(i),24,41)

                        
    Log("MAC Address of Alive "&MACAddress)
    Log("IP address of alive "&ipaddress)
Dim ip As Int = su.SubstringAfterLast(ipaddress,".")
    Log(" IP last digits "&ip)
    If ip < 200 Then
                Wait For(pingesp(ipaddress)) Complete (result As Boolean)
    End If
            If result=True Then   
                Dim whereas As Map
                whereas.Initialize
                whereas.Put("macaddress",MACAddress)
                DBUtils.UpdateRecord(sql1,"dfip","alive",1,whereas)
            End If
reloadtables
        End If
    Next
End Sub



Thank you
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
I think so. But what exactly do you want to achieve?
There are many free DHCP server SW, why create another one?

DHCP uses the UDP protocol, the registered ports are 67 for the server and 68 for the client.
There must not be another DHCP server listening, it would only create difficulties. The server in B4J would listen on port 67 and process the request
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
After you edit the message, the request looks different.
Do you want to create a DHCP server to know for sure which IP addresses are active?
Haven't you thought about just pinging the subnet and waiting for responses?
(the topic of the thread is misleading)
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
I think so. But what exactly do you want to achieve?
There are many free DHCP server SW, why create another one?

I am using a DHCP server which has an .ini file which I update. It does work pretty well, I just wanted everything in one program without having to rely on an external program.

I give each MAC address a temp IP Address and then When my program allocated a new IP for a MAC address , it updates the EXTERNAL DHCP server which then updates the product with a new IP. The product IP has to change depends on which sequence it is placed in , each time might be different. It is only used in a configuration for a few hours then the units are either moved or replaced. After this the IP adresses have to be in order
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
After you edit the message, the request looks different.
Do you want to create a DHCP server to know for sure which IP addresses are active?
Haven't you thought about just pinging the subnet and waiting for responses?
(the topic of the thread is misleading)
Sorry about that, It is a two part question. A DHCP server is my first prize along with checking on MAC adresses, Ping will not give that to me
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
It will help you
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Maybe if you have knowledge how to made a Java wrapper: perhaps you can use the open-source Jagornet DHCP Server. It supports:
  • Static bindings (reservations)
  • Client filtering (client classes)
  • Dynamic DNS updates
  • Platform independent (Java 8+)
  • Highly scalable, multithreaded architecture featuring Netty
  • Flexible XML, JSON, or YAML configuration file format (new for v3.1.0)
 
Upvote 0
Top