Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)

2,087 views

Published on

Source Code of Building Linux IPv6 DNS Server (Complete Source code)

Published in: Technology, News & Politics
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
2,087
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
0
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)

  1. 1. Building a Linux IPv6 DNS Server /*Loading .sh (Shell Script) */ putChar() { i=1 while [ $i -le $3 ] do echo -n quot;$1quot; sleep $2 i=`expr $i + 1` done } clear echo putChar _ 0 80 echo -e quot;nquot; echo quot; !!! Loading System Detailsquot; echo -ne quot;nttit may take few seconds quot; sleep 1 putChar '.' 0.25 20 putChar '.' 0 20 putChar _ 0 80 sleep 1 echo -ne quot;nnnt--> Checking system details quot; putChar '.' 0.5 8 echo -e quot;nntt-- Machine (hardware) type : `uname -m`quot; Page 54
  2. 2. Building a Linux IPv6 DNS Server sleep 2 echo -e quot;tt-- Machine's network hostname : `uname -n`quot; sleep 1 echo -e quot;tt-- Operating system release : `uname -r`quot; sleep 0.5 echo -e quot;tt-- Operating system name : `uname -s`quot; sleep 0.5 echo -e quot;tt-- Host processor type : `uname -p`quot; sleep 0.25 echo -e quot;tt-- Operating system version : `uname -v`quot; sleep 1 echo -ne quot;nnt--> Checking for root user privilege quot; putChar '.' 0.5 6 sleep 1 if [ quot;`whoami`quot; != quot;rootquot; ] then echo -e quot;nntt-- Sorry this software has to be run by root user....nnquot; sleep 2 echo -e quot;nttAborting.......quot;; sleep 5 exit else sh run.sh echo -e quot;nntt-- found root user privileges !quot; sleep 1 echo -ne quot;nntttttttt quot; putChar '->' 0.25 5 Page 55
  3. 3. Building a Linux IPv6 DNS Server sleep 1 echo -e quot;nquot; fi /* Builder.c [C source File] */ #include <unistd.h> #include <stdio.h> #include <dirent.h> #include <string.h> #include <sys/stat.h> #include <stdlib.h> void printChar(char c, int count) { int i; for(i=0; i<count; i++) printf(quot;%cquot;, c); printf(quot;nquot;); } // end printChar void bu() { system(quot;sh built.shquot;); } void Builder() { char ans, dirName[260]; char dir,command[260]; FILE *fp = fopen(quot;SourceDirquot;, quot;rquot;); fscanf(fp, quot;%squot;, dirName); Page 56
  4. 4. Building a Linux IPv6 DNS Server fclose(fp); printf(quot;Enter the Dir. Name Default is '%s' is it o.k (y/n): quot;, dirName); scanf(quot; %cquot;, &dir); if(dir == 'y') { printf(quot;Ensure that U have copied the source files..quot;); printf(quot;Shall I Proceed...(y/n): quot;); scanf(quot; %cquot;, &ans); if(ans == 'y') { chdir(dirName); // system(quot;cp -rf /usr/src/linux-2.4.21-4.EL/arch/i386/defconfig /usr/src/linux- 2.4.21-4.EL/arch/i386/defconfig.orgquot;); printChar('/',79); printChar('/',79); printf(quot;nquot;); printf(quot;Press Any key to proceed with cleaning...quot;); getchar(); getchar(); printChar('/',79); printChar('/',79); system(quot;sleep 40quot;); printf(quot;nquot;); printf(quot;Press Any key to proceed with kernel image creation...quot;); getchar(); /* system(quot;make bzImage &> /dev/zeroquot;);*/ bu(); system(quot;sleep 60quot;); printChar('*', 79); printChar('*', 79); Page 57
  5. 5. Building a Linux IPv6 DNS Server printChar('*', 79); //strcpy(command,quot;cp /Project/ntfssupportedkernel arch/i386/boot/bzImagequot;); //system(command); printf(quot;nProcess Completed Successfully!!!nnquot;); } } else { printf(quot;Enter the directory Name: quot;); scanf(quot;%squot;, dirName); printf(quot;Ensure that U have copied the source files..quot;); printf(quot;Shall I Proceed...(y/n): quot;); scanf(quot; %cquot;, &ans); printf(quot;ans is %cnquot;, ans); if(ans == 'y') { chdir(dirName); system(quot;make dep &> /dev/zeroquot;); // system(quot;make dep | tee .o; ./.squot;); printChar('/',79); printChar('/',79); printf(quot;nquot;); printf(quot;Press Any key to proceed with cleaning...quot;); getchar(); getchar(); system(quot;sleep 60quot;); printChar('/',79); printChar('/',79); printf(quot;nquot;); printf(quot;Press Any key to proceed with kernel image creation...quot;); getchar(); Page 58
  6. 6. Building a Linux IPv6 DNS Server printChar('/',79); printChar('/',79); printf(quot;nquot;); //system(quot;sleep 60quot;); printChar('*', 79); system(command); printChar('*', 79); printf(quot;Process Completed Successfully!!!nnquot;); } } } // end Builder int main() { Builder(); } // end main /* Dir Handler.c [C source File] */ #include <unistd.h> #include <stdio.h> #include <dirent.h> #include <string.h> #include <sys/stat.h> #include <stdlib.h> void PrintDir(char *dirName, int depth) { DIR *dp; struct dirent *entry; struct stat statbuf; if((dp = opendir(dirName)) == NULL) { fprintf(stderr, quot;Cann't open Directory: %snquot;, dirName); return; Page 59
  7. 7. Building a Linux IPv6 DNS Server } chdir(dirName); while((entry = readdir(dp)) != NULL) { lstat(entry->d_name, &statbuf); if(S_ISDIR(statbuf.st_mode)) { /* ignore . and .. */ if(strcmp(quot;.quot;, entry->d_name) == 0 || strcmp(quot;..quot;, entry->d_name)==0) continue; printf(quot;%s/nquot;, entry->d_name); } // end if } // end while } // end PrintDir void DirHandler() { FILE *fp = fopen(quot;SourceDirquot;, quot;wquot;); char dirName[81]; char command[200]; char cmd[250]; char srcName[260], destName[260]; char pro; char defDir[] = quot;/usr/src/quot;; char srcRel[50], destRel[50]; printf(quot;Enter the Dir To be scanned: quot;); scanf(quot;%squot;, dirName); PrintDir(dirName, 0); printf(quot;nn... That's all folks...nquot;); printf(quot;The default dir is '%s' Shall I proceed? (y/n): quot;, defDir); scanf(quot; %cquot;, &pro); if(pro == 'n') { Page 60
  8. 8. Building a Linux IPv6 DNS Server printf(quot;Enter the Directory U want to be backed up: quot;); scanf(quot;%squot;, srcName); printf(quot;Now Enter the Directory name U want the sources to be in: quot;); scanf(quot;%squot;, destName); command[0]='0'; strcat(command, quot;cp -r quot;); strcat(command, srcName); strcat(command, quot; quot;); strcat(command, destName); cmd[0] = '0'; strcat(cmd, command); printf(quot;n Command %squot;,cmd); printf(quot;nPress any key to go ahead with backup....quot;); printf(quot;This process may take several minutes... pls. wait....quot;); /* getchar(); getchar(); printf(quot;n Command %s quot;, command);*/ getchar(); system(command); printf(quot;nProcess Completed Successfully!!!nnquot;); } else { printf(quot;Enter the Directory U want to be backed up: quot;); scanf(quot;%squot;, srcRel); srcName[0]='0'; strcpy(srcName, defDir); strcat(srcName, srcRel); printf(quot;Now Enter the Directory name U want the sources to be in: quot;); scanf(quot;%squot;, destRel); Page 61
  9. 9. Building a Linux IPv6 DNS Server strcpy(destName, defDir); strcat(destName, destRel); command[0]='0'; strcat(command, quot;cp -r quot;); strcat(command, srcName); strcat(command, quot; quot;); strcat(command, destName); printf(quot;nPress any key to go ahead with backup....quot;); printf(quot;This process may take several minutes... pls. wait....quot;); getchar(); getchar(); system(command); printf(quot;nProcess Completed Successfully!!!nnquot;); } fprintf(fp, quot;%squot;, destName); fclose(fp); } // end DirHandler int main() { DirHandler(); } /* MemberAdderGUI (Server Side) */ import java.net.*; import java.awt.*; import java.util.*; import javax.swing.*; Page 62
  10. 10. Building a Linux IPv6 DNS Server import java.awt.event.*; public class MemberAdderGUI extends JFrame { ServerSocket serverSocket; int DEFAULT_PORT=111; int port; Vector membersList; JFrame frame; TextField tfStatus; Container c; JPanel pnlPortInfo; JTextField jtfPort; JButton btnAction; java.awt.List lstMembers; String strBtnCaption = quot;quot;; Thread memberAdder; public MemberAdderGUI(String title) { super(title); membersList = new Vector(); frame = this; c = getContentPane(); strBtnCaption = quot;Startquot;; pnlPortInfo = new JPanel(); pnlPortInfo.setLayout(new BorderLayout()); pnlPortInfo.add(quot;Westquot;, new JLabel(quot;Port: quot;)); Page 63
  11. 11. Building a Linux IPv6 DNS Server pnlPortInfo.add(quot;Centerquot;, jtfPort = new JTextField(7)); pnlPortInfo.add(quot;Eastquot;, btnAction = new JButton(strBtnCaption)); btnAction.addActionListener(new Axn()); c.add(quot;Northquot;, pnlPortInfo); c.add(quot;Centerquot;, lstMembers = new java.awt.List(7)); c.add(quot;Southquot;, tfStatus = new TextField()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(300, 300); setLocation(70, 70); setVisible(true); } public MemberAdderGUI(int port) { this.port = port; membersList = new Vector(); } class MemberAdder implements Runnable { public void run() { try { serverSocket = new ServerSocket(port); System.out.println(quot;Member Adder started and waiting...at 'quot; + port + quot;'..!!quot;); Socket clientSocket = null; while(true) Page 64
  12. 12. Building a Linux IPv6 DNS Server { clientSocket = serverSocket.accept(); System.out.println(quot;Connected to machine: quot; + clientSocket); String ipAddress = clientSocket.getInetAddress().getHostAddress(); clientSocket.close(); addMember(ipAddress); printMembers(); } } catch(Exception e) { } } // end run } // end MemberAdder public void addMember(String ipAddress) { if(!membersList.contains(ipAddress)) { membersList.add(ipAddress); lstMembers.add(ipAddress); tfStatus.setText(quot;Added 'quot; + ipAddress + quot;' Successfully!!quot;); } else { System.out.println(quot;quot;quot; + ipAddress + quot;quot; has been added already!!!quot;); tfStatus.setText(quot;quot;quot; + ipAddress + quot;quot; has been added already!!!quot;); } } Page 65
  13. 13. Building a Linux IPv6 DNS Server public void printMembers() { System.out.println(quot;nnList of Available members is..nquot;); Enumeration list = membersList.elements(); while(list.hasMoreElements()) { System.out.println((String)list.nextElement()); } System.out.println(quot;-----------------------that's all-----------------------quot;); } class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCommand = ae.getActionCommand(); try { if(strCommand.equals(quot;Startquot;)) { strBtnCaption = quot;Stopquot;; btnAction.setText(strBtnCaption); if(jtfPort.getText().equals(quot;quot;)) { port = DEFAULT_PORT; } else Page 66
  14. 14. Building a Linux IPv6 DNS Server { port = Integer.parseInt(jtfPort.getText()); } if(memberAdder == null) { memberAdder = new Thread(new MemberAdder()); memberAdder.start(); } else { memberAdder = null; System.gc(); } } else if(strCommand.equals(quot;Stopquot;)) { strBtnCaption = quot;Startquot;; btnAction.setText(strBtnCaption); serverSocket.close(); serverSocket = null; System.gc(); } } catch(Exception e) { System.out.println(quot;MemberAdderGUI: Axn: quot; + e); } // end try-catch Page 67
  15. 15. Building a Linux IPv6 DNS Server } // end action } // end Axn public static void main(String [] args) { new MemberAdderGUI(quot;Member Listquot;); } } // end MemberAdderGUI /* AddMeAsMemberGUI (Client Side)*/ import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class AddMeAsMemberGUI extends JFrame { String host; int port; JTextField jtfHost, jtfPort; JPanel pnlHostInfo, pnl1, pnl2, pnlActions; JFrame frame; Container c; JButton btnRegister, btnClose; public AddMeAsMemberGUI(String title) { Page 68
  16. 16. Building a Linux IPv6 DNS Server c = getContentPane(); setTitle(title); frame = this; pnlHostInfo = new JPanel(); pnlHostInfo.setLayout(new BorderLayout()); pnl1 = new JPanel(); pnl1.setLayout(new GridLayout(2, 1)); pnl1.add(jtfHost = new JTextField(15)); pnl1.add(jtfPort = new JTextField(15)); pnl2 = new JPanel(); pnl2.setLayout(new GridLayout(2, 1)); pnl2.add(new JLabel(quot;Host: quot;)); pnl2.add(new JLabel(quot;Port: quot;)); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnRegister = new JButton(quot;Registerquot;)); btnRegister.addActionListener(new Axn()); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnClose.addActionListener(new Axn()); pnlHostInfo.add(quot;Centerquot;, pnl1); pnlHostInfo.add(quot;Westquot;, pnl2); pnlHostInfo.add(quot;Southquot;, pnlActions); c.add(quot;Centerquot;, pnlHostInfo); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(200, 110); setLocation(80, 80); setVisible(true); } // end cons Page 69
  17. 17. Building a Linux IPv6 DNS Server class AddMe implements Runnable { public void run() { try { Socket clientSocket = new Socket(host, port); } catch(Exception e) { System.out.println(quot;AddMe: Axn: quot; + e); } } // end run } // end AddMe public class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCmd = ae.getActionCommand(); if(strCmd.equals(quot;Registerquot;)) { host = jtfHost.getText(); port = Integer.parseInt(jtfPort.getText()); new Thread(new AddMe()).start(); } else if(strCmd.equals(quot;Closequot;)) { Page 70
  18. 18. Building a Linux IPv6 DNS Server frame.dispose(); } } } // end Axn public static void main(String [] args) { new AddMeAsMemberGUI(quot;Add Me As MEMBERquot;); } } // end AddMeAsMemberGUI /* LookUp Server GUI (Server Side) */ import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class LookUpServerGUI extends JFrame { ServerSocket serverSok; JButton btnStart, btnStop; JTextField jtfPort; JPanel pnlActions, pnlPortInfo; boolean stopServer; Thread lookupSvr; Container c; Page 71
  19. 19. Building a Linux IPv6 DNS Server public LookUpServerGUI(String title) { super(title); c = getContentPane(); pnlPortInfo = new JPanel(); pnlPortInfo.setLayout(new GridLayout(1, 2)); pnlPortInfo.add(new JLabel(quot;Port: quot;)); pnlPortInfo.add(jtfPort = new JTextField(4)); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(2, 1)); pnlActions.add(btnStart = new JButton(quot;Startquot;)); pnlActions.add(btnStop = new JButton(quot;Stopquot;)); btnStart.addActionListener(new Axn()); btnStop.addActionListener(new Axn()); c.add(quot;Northquot;, pnlPortInfo); c.add(quot;Centerquot;, pnlActions); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize(100, 100); setLocation(70, 70); setVisible(true); } // end cons class LookupServer implements Runnable { public void run() { try Page 72
  20. 20. Building a Linux IPv6 DNS Server { int port; stopServer = false; String strPort = jtfPort.getText(); if(!strPort.equals(quot;quot;)) { port = Integer.parseInt(strPort); } else { port = 1234; } If (serverSok == null) { serverSok = new ServerSocket(port); } else { ; // do NOTHING } while(stopServer == false) { System.out.println(quot;Waiting....at 'quot; + port + quot;'quot;); Socket clientSok = serverSok.accept(); System.out.println(quot;Connected to: quot; + clientSok); PrintWriter toClient = new PrintWriter(clientSok.getOutputStream(), true); toClient.println(quot;Activequot;); Page 73
  21. 21. Building a Linux IPv6 DNS Server toClient.flush(); clientSok.close(); } // end while } catch(Exception e) { System.out.println(quot;LookupServer: quot; + e); } } // end run } public class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCmd = ae.getActionCommand(); try { if(strCmd.equals(quot;Startquot;)) { if(lookupSvr == null) { lookupSvr = new Thread(new LookupServer()); lookupSvr.start(); } else { System.out.println(quot;Already Running!!!!quot;); Page 74
  22. 22. Building a Linux IPv6 DNS Server } } else if(strCmd.equals(quot;Stopquot;)) { stopServer = true; serverSok.close(); serverSok = null; lookupSvr = null; System.gc(); System.out.println(quot;Stopped!!quot;); } // end if } catch(Exception e) { System.out.println(e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new LookUpServerGUI(quot;Lookup Serverquot;); } } // end LookUpServerGUI /* LookUpClientGUI */ Page 75
  23. 23. Building a Linux IPv6 DNS Server import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class LookUpClientGUI extends JFrame { String host; int port; JTextField jtfHost, jtfPort; JPanel pnlHostInfo, pnl1, pnlActions; JFrame frame; Container c; TextField tfStatus; JButton btnLookup, btnClose; public LookUpClientGUI(String title) { c = getContentPane(); setTitle(title); frame = this; pnlHostInfo = new JPanel(); pnlHostInfo.setLayout(new BorderLayout()); pnl1 = new JPanel(); pnl1.setLayout(new GridLayout(2, 2)); pnl1.add(new JLabel(quot;Host: quot;)); pnl1.add(jtfHost = new JTextField(15)); Page 76
  24. 24. Building a Linux IPv6 DNS Server pnl1.add(new JLabel(quot;Port: quot;)); pnl1.add(jtfPort = new JTextField(15)); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnLookup = new JButton(quot;Lookupquot;)); btnLookup.addActionListener(new Axn()); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnClose.addActionListener(new Axn()); pnlHostInfo.add(quot;Centerquot;, pnl1); pnlHostInfo.add(quot;Southquot;, pnlActions); c.add(quot;Centerquot;, pnlHostInfo); c.add(quot;Southquot;, tfStatus = new TextField()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(200, 135); setLocation(70, 70); setVisible(true); } // end cons public class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCmd = ae.getActionCommand(); if(strCmd.equals(quot;Lookupquot;)) { host = jtfHost.getText(); port = Integer.parseInt(jtfPort.getText()); Page 77
  25. 25. Building a Linux IPv6 DNS Server new Thread(new LookupClient()).start(); } else if(strCmd.equals(quot;Closequot;)) { frame.dispose(); } } } // end Axn public void run() { try { Socket clientSok = new Socket(host, port); BufferedReader fromServer = new BufferedReader(new InputStreamReader(clientSok.getInputStream())); String answer = fromServer.readLine(); if(answer.equals(quot;Activequot;)) { System.out.println(quot;The Server is active...quot;); tfStatus.setText(quot;The Server is ACTIVE...quot;); } } catch(Exception e) { System.out.println(quot;Exception has come the server seems to be NOT ACTIVE..quot;); tfStatus.setText(quot;server seems to be NOT ACTIVE..quot;); } // end try-catch Page 78
  26. 26. Building a Linux IPv6 DNS Server } // end run } // end LookupClient public static void main(String [] args) { new LookUpClientGUI(quot;Lookup Clientquot;); } } // end LookUpClientGUI /* DNSmain (Server Side) */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DNSmain extends JFrame { JMenuBar mbar; JMenu mnuDNS, mnuHelp; JMenuItem jmi; JFrame frame; Container c; JDesktopPane jdp; public DNSmain(String title) { super(title); frame = this; Page 79
  27. 27. Building a Linux IPv6 DNS Server c = getContentPane(); jdp = new JDesktopPane(); c.add(jdp); mbar = new JMenuBar(); mnuDNS = new JMenu(quot;DNSquot;); jmi = new JMenuItem(quot;Control Panelquot;, 'C'); jmi.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); mnuDNS.addSeparator(); jmi = new JMenuItem(quot;IPv6 Addressquot;, 'I'); jmi.setAccelerator(KeyStroke.getKeyStroke('I', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); jmi = new JMenuItem(quot;IPv4 Addressquot;, 'A'); jmi.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); mnuDNS.addSeparator(); jmi = new JMenuItem(quot;Exitquot;, 'X'); jmi.setAccelerator(KeyStroke.getKeyStroke('X', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); mnuHelp = new JMenu(quot;Helpquot;); Page 80
  28. 28. Building a Linux IPv6 DNS Server jmi = new JMenuItem(quot;Contentsquot;, 'C'); jmi.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuHelp.add(jmi); jmi = new JMenuItem(quot;Search...quot;, 'S'); jmi.setAccelerator(KeyStroke.getKeyStroke('S', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuHelp.add(jmi); mnuHelp.addSeparator(); jmi = new JMenuItem(quot;Aboutquot;, 'A'); jmi.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuHelp.add(jmi); mbar.add(mnuDNS); mbar.add(mnuHelp); setJMenuBar(mbar); setDefaultCloseOperation(0); addWindowListener(new WinLstner()); setLocation(50, 50); setSize(600, 500); setVisible(true); } // end cons class Axn implements ActionListener { Page 81
  29. 29. Building a Linux IPv6 DNS Server public void actionPerformed(ActionEvent ae) { String cmdString = ae.getActionCommand(); if(cmdString.equals(quot;Exitquot;)) { int result = JOptionPane.showConfirmDialog(frame, quot;Do you Really want to quit?quot;, quot;Quitting?quot;, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if(result == JOptionPane.YES_OPTION) frame.dispose(); } else if(cmdString.equals(quot;Control Panelquot;)) { JInternalFrame jif = new DNSpanelIF(quot;DNS panelquot;); jdp.add(jif); } else if(cmdString.equals(quot;IPv6 Addressquot;)) { JInternalFrame jif = new Ipv6RecordAdderIF(quot;IPv6 DNS Recordsquot;); jdp.add(jif); } else if(cmdString.equals(quot;IPv4 Addressquot;)) { JInternalFrame jif = new Ipv4RecordAdderIF(quot;IPv4 DNS Recordsquot;); jdp.add(jif); } } // end action Page 82
  30. 30. Building a Linux IPv6 DNS Server } // end Axn class WinLstner extends WindowAdapter { public void windowClosing(WindowEvent we) { int result = JOptionPane.showConfirmDialog(frame, quot;Do you Really want to quit?quot;, quot;Quitting?quot;, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if(result == JOptionPane.YES_OPTION) frame.dispose(); } } // end WinLstner public static void main(String [] args) { new DNSmain(quot;IPv6 ready DNSquot;); } // end main } // end DNSmain /* DNShandler */ import java.io.*; public class DNShandler { public void startDNS() { Page 83
  31. 31. Building a Linux IPv6 DNS Server try { Runtime r = Runtime.getRuntime(); Process p = r.exec(quot;service named startquot;); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = quot;quot;; while((line = br.readLine()) != null) System.out.println(line); } catch(Exception e) { System.out.println(quot;startDNS:: quot; + e); } } public void stopDNS() { try { Runtime r = Runtime.getRuntime(); Process p = r.exec(quot;service named stopquot;); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = quot;quot;; while((line = br.readLine()) != null) System.out.println(line); } Page 84
  32. 32. Building a Linux IPv6 DNS Server catch(Exception e) { System.out.println(quot;stopDNS:: quot; + e); } } public void reloadDNS() { try { Runtime r = Runtime.getRuntime(); Process p = r.exec(quot;service named reloadquot;); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = quot;quot;; while((line = br.readLine()) != null) System.out.println(line); } catch(Exception e) { System.out.println(quot;reloadDNS:: quot; + e); } } public static void main(String [] args) { new DNShandler().reloadDNS(); Page 85
  33. 33. Building a Linux IPv6 DNS Server } // end main } // end DNShandler /* DNS Panel (Server side) */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DNSpanel extends JFrame { JPanel pnlActions; JButton btnStart, btnStop, btnRestart, btnClose; JFrame frame; Container c; public DNSpanel(String title) { super(title); c = getContentPane(); frame = this; pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(2, 2)); pnlActions.add(btnStart = new JButton(quot;Startquot;)); pnlActions.add(btnStop = new JButton(quot;Stopquot;)); pnlActions.add(btnRestart = new JButton(quot;Restartquot;)); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnStart.addActionListener(new Axn()); btnStop.addActionListener(new Axn()); Page 86
  34. 34. Building a Linux IPv6 DNS Server btnRestart.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(pnlActions); setLocation(70, 70); setSize(200, 100); setVisible(true); } // end DNspanel class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCommand = ae.getActionCommand(); if(strCommand.equals(quot;Startquot;)) { new DNShandler().startDNS(); } else if(strCommand.equals(quot;Stopquot;)) { new DNShandler().stopDNS(); } else if(strCommand.equals(quot;Restartquot;)) { new DNShandler().reloadDNS(); } else if(strCommand.equals(quot;Closequot;)) { frame.dispose(); Page 87
  35. 35. Building a Linux IPv6 DNS Server } } // end action } // end Axn public static void main(String [] args) { new DNSpanel(quot;DNS panelquot;); } // end main } // end DNSpanel /* DNS panel IF (Internal Frame) */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DNSpanelIF extends JInternalFrame { JPanel pnlActions; JButton btnStart, btnStop, btnRestart, btnClose; JInternalFrame frame; Container c; public DNSpanelIF(String title) { super(title); c = getContentPane(); frame = this; pnlActions = new JPanel(); Page 88
  36. 36. Building a Linux IPv6 DNS Server pnlActions.setLayout(new GridLayout(2, 2)); pnlActions.add(btnStart = new JButton(quot;Startquot;)); pnlActions.add(btnStop = new JButton(quot;Stopquot;)); pnlActions.add(btnRestart = new JButton(quot;Restartquot;)); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnStart.addActionListener(new Axn()); btnStop.addActionListener(new Axn()); btnRestart.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(pnlActions); setClosable(true); setResizable(true); setMaximizable(true); setIconifiable(true); setLocation(70, 70); setSize(200, 100); setVisible(true); } // end DNspanel class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCommand = ae.getActionCommand(); if(strCommand.equals(quot;Startquot;)) { new DNShandler().startDNS(); } Page 89
  37. 37. Building a Linux IPv6 DNS Server else if(strCommand.equals(quot;Stopquot;)) { new DNShandler().stopDNS(); } else if(strCommand.equals(quot;Restartquot;)) { new DNShandler().reloadDNS(); } else if(strCommand.equals(quot;Closequot;)) { frame.dispose(); } } // end action } // end Axn public static void main(String [] args) { new DNSpanelIF(quot;DNS panelquot;); } // end main } // end DNSpanelIF /* Ipv4RecordAdder */ import java.io.*; import java.net.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; Page 90
  38. 38. Building a Linux IPv6 DNS Server public class Ipv4RecordAdder extends JFrame { String zoneFileName; String dnsDirectory = quot;/var/named/quot;; // DEFAULT DIRECTORY JTextField jtfDomainName, jtfHostName, jtfAddress; JButton btnAdd, btnClose; JPanel pnlActions, pnlCenter; JFrame frame; Container c; public Ipv4RecordAdder(String title) { super(title); frame = this; c = getContentPane(); pnlCenter = new JPanel(); pnlCenter.setLayout(new GridLayout(3, 2)); pnlCenter.add(new JLabel(quot;Domain Name : quot;)); pnlCenter.add(jtfDomainName = new JTextField()); pnlCenter.add(new JLabel(quot;Host Name : quot;)); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(quot;IPv4 Address: quot;)); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnAdd = new JButton(quot;Addquot;)); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnAdd.addActionListener(new Axn()); Page 91
  39. 39. Building a Linux IPv6 DNS Server btnClose.addActionListener(new Axn()); c.add(quot;Centerquot;, pnlCenter); c.add(quot;Southquot;, pnlActions); setDefaultCloseOperation(1); setLocation(70, 70); setSize(280, 150); setVisible(true); } // end cons class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String cmdString = ae.getActionCommand(); try { if(cmdString.equals(quot;Addquot;)) { String domainName = jtfDomainName.getText(); String zoneFileName = dnsDirectory + domainName + quot;.zonequot;; String hostName = jtfHostName.getText(); String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + quot;tINtAtquot; + ipAddress); System.out.println(quot;Record Added Successfully!!!!quot;); // Clear the TextFields Page 92
  40. 40. Building a Linux IPv6 DNS Server jtfDomainName.setText(quot;quot;); jtfHostName.setText(quot;quot;); jtfAddress.setText(quot;quot;); zoneFile.close(); } else if(cmdString.equals(quot;Closequot;)) { frame.dispose(); } } catch(Exception e) { System.out.println(quot;Ipv4 Add: quot; + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new Ipv4RecordAdder(quot;IPv4 Record Adder..quot;); } // end main } // end Ipv4RecordAdder /* Ipv4RecordAdderIF (Internal Frame) */ import java.io.*; import java.net.*; import java.awt.*; Page 93
  41. 41. Building a Linux IPv6 DNS Server import javax.swing.*; import java.awt.event.*; public class Ipv4RecordAdderIF extends JInternalFrame { String zoneFileName; String dnsDirectory = quot;/var/named/quot;; // DEFAULT DIRECTORY JTextField jtfDomainName, jtfHostName, jtfAddress; JButton btnAdd, btnClose; JPanel pnlActions, pnlCenter; JInternalFrame frame; Container c; public Ipv4RecordAdderIF(String title) { super(title); frame = this; c = getContentPane(); pnlCenter = new JPanel(); pnlCenter.setLayout(new GridLayout(3, 2)); pnlCenter.add(new JLabel(quot;Domain Name : quot;)); pnlCenter.add(jtfDomainName = new JTextField()); pnlCenter.add(new JLabel(quot;Host Name : quot;)); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(quot;IPv4 Address: quot;)); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); Page 94
  42. 42. Building a Linux IPv6 DNS Server pnlActions.add(btnAdd = new JButton(quot;Addquot;)); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnAdd.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(quot;Centerquot;, pnlCenter); c.add(quot;Southquot;, pnlActions); setDefaultCloseOperation(1); setClosable(true); setResizable(true); setMaximizable(true); setIconifiable(true); setLocation(70, 70); setSize(280, 150); setVisible(true); } // end cons class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String cmdString = ae.getActionCommand(); try { if(cmdString.equals(quot;Addquot;)) { String domainName = jtfDomainName.getText(); String zoneFileName = dnsDirectory + domainName + quot;.zonequot;; String hostName = jtfHostName.getText(); Page 95
  43. 43. Building a Linux IPv6 DNS Server String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + quot;tINtAtquot; + ipAddress); System.out.println(quot;Record Added Successfully!!!!quot;); // Clear the TextFields jtfDomainName.setText(quot;quot;); jtfHostName.setText(quot;quot;); jtfAddress.setText(quot;quot;); zoneFile.close(); } else if(cmdString.equals(quot;Closequot;)) { frame.dispose(); } } catch(Exception e) { System.out.println(quot;Ipv4 Add: quot; + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new Ipv4RecordAdderIF(quot;IPv4 Record Adder..quot;); } // end main } // end Ipv4RecordAdderIF Page 96
  44. 44. Building a Linux IPv6 DNS Server /* Ipv6RecordAdder */ import java.io.*; import java.net.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Ipv6RecordAdder extends JFrame { String zoneFileName; String dnsDirectory = quot;/var/named/quot;; // DEFAULT DIRECTORY JTextField jtfDomainName, jtfHostName, jtfAddress; J Button btnAdd, btnClose; JPanel pnlActions, pnlCenter; JFrame frame; Container c; public Ipv6RecordAdder(String title) { super(title); frame = this; c = getContentPane(); pnlCenter = new JPanel(); pnlCenter.setLayout(new GridLayout(3, 2)); pnlCenter.add(new JLabel(quot;Domain Name : quot;)); pnlCenter.add(jtfDomainName = new JTextField()); Page 97
  45. 45. Building a Linux IPv6 DNS Server pnlCenter.add(new JLabel(quot;Host Name : quot;)); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(quot;IPv6 Address: quot;)); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnAdd = new JButton(quot;Addquot;)); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnAdd.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(quot;Centerquot;, pnlCenter); c.add(quot;Southquot;, pnlActions); setDefaultCloseOperation(1); setLocation(70, 70); setSize(280, 150); setVisible(true); } // end cons class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String cmdString = ae.getActionCommand(); try { if(cmdString.equals(quot;Addquot;)) { String domainName = jtfDomainName.getText(); Page 98
  46. 46. Building a Linux IPv6 DNS Server String zoneFileName = dnsDirectory + domainName + quot;.zonequot;; String hostName = jtfHostName.getText(); String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + quot;ttINtAAAAtquot; + ipAddress); System.out.println(quot;Record Added Successfully!!!!quot;); // Clear the TextFields jtfDomainName.setText(quot;quot;); jtfHostName.setText(quot;quot;); jtfAddress.setText(quot;quot;); zoneFile.close(); } else if(cmdString.equals(quot;Closequot;)) { frame.dispose(); } } catch(Exception e) { System.out.println(quot;Ipv6 Add: quot; + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { Page 99
  47. 47. Building a Linux IPv6 DNS Server new Ipv6RecordAdder(quot;IPv6 Record Adder..quot;); } // end main } // end Ipv6RecordAdder /* Ipv6RecordAdderIF (Internal Frame) */ import java.io.*; import java.net.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Ipv6RecordAdderIF extends JInternalFrame { String zoneFileName; String dnsDirectory = quot;/var/named/quot;; // DEFAULT DIRECTORY JTextField jtfDomainName, jtfHostName, jtfAddress; JButton btnAdd, btnClose; JPanel pnlActions, pnlCenter; JInternalFrame frame; Container c; public Ipv6RecordAdderIF(String title) { super(title); frame = this; c = getContentPane(); pnlCenter = new JPanel(); pnlCenter.setLayout(new GridLayout(3, 2)); Page 100
  48. 48. Building a Linux IPv6 DNS Server pnlCenter.add(new JLabel(quot;Domain Name : quot;)); pnlCenter.add(jtfDomainName = new JTextField()); pnlCenter.add(new JLabel(quot;Host Name : quot;)); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(quot;IPv6 Address: quot;)); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnAdd = new JButton(quot;Addquot;)); pnlActions.add(btnClose = new JButton(quot;Closequot;)); btnAdd.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(quot;Centerquot;, pnlCenter); c.add(quot;Southquot;, pnlActions); setClosable(true); setResizable(true); setMaximizable(true); setIconifiable(true); setDefaultCloseOperation(1); setLocation(70, 70); setSize(280, 150); setVisible(true); } // end cons class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) Page 101
  49. 49. Building a Linux IPv6 DNS Server { String cmdString = ae.getActionCommand(); try { if(cmdString.equals(quot;Addquot;)) { String domainName = jtfDomainName.getText(); String zoneFileName = dnsDirectory + domainName + quot;.zonequot;; String hostName = jtfHostName.getText(); String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + quot;ttINtAAAAtquot; + ipAddress); System.out.println(quot;Record Added Successfully!!!!quot;); // Clear the TextFields jtfDomainName.setText(quot;quot;); jtfHostName.setText(quot;quot;); jtfAddress.setText(quot;quot;); zoneFile.close(); } else if(cmdString.equals(quot;Closequot;)) { frame.dispose(); } } catch(Exception e) Page 102
  50. 50. Building a Linux IPv6 DNS Server { System.out.println(quot;Ipv6 Add: quot; + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new Ipv6RecordAdderIF(quot;IPv6 Record Adder..quot;); } // end main } // end Ipv6RecordAdderIF /* Address Handler (Server Side) */ import java.io.*; import java.net.*; public class AddressHandler { public AddressHandler() { try { // System.out.println(Inet6Address().numericToTextForm at()); ServerSocket sok = new ServerSocket(2995); System.out.println(quot;Server Ready!!!quot;); Socket client = sok.accept(); Page 103
  51. 51. Building a Linux IPv6 DNS Server System.out.println(client); BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream())); String line = br.readLine(); System.out.println(quot;Client has sent...quot; + line); } catch(Exception e) { System.out.println(e); } // end try-catch } // end cons public static void main(String [] args) { new AddressHandler(); } } /* Client (Client Side) */ import java.io.*; import java.net.*; public class Client { public Client(String host, int port) { try { System.out.println(Inet6Address().numericToTextFormat()); Page 104
  52. 52. Building a Linux IPv6 DNS Server Socket sok = new Socket(host, port); System.out.print(quot;Enter some text: quot;); String line = new BufferedReader(new InputStreamReader(System.in)).readLine(); PrintWriter out = new PrintWriter(sok.getOutputStream()); out.println(line); out.flush(); } catch(Exception e) { System.out.println(e); } // end try-catch } // end cons public static void main(String [] args) { new Client(args[0], Integer.parseInt(args[1])); } } Page 105
  53. 53. Building a Linux IPv6 DNS Server /* A Typical view of Named.conf Configuration file */ ## named.conf - configuration for bind # # Generated automatically by redhat-config-bind, alchemist et al. # Any changes not supported by redhat-config-bind should be put # in /etc/named.custom # controls { inet 127.0.0.1 allow { localhost; } keys { rndckey; }; }; include quot;/etc/named.customquot;; include quot;/etc/rndc.keyquot;; #options { # listen-on-v6 { any; }; #}; zone quot;localhostquot; { type master; file quot;localhost.zonequot;; }; zone quot;mahendra.comquot; { type master; file quot;mahendra.com.zonequot;; }; Page 106
  54. 54. Building a Linux IPv6 DNS Server /* A Typical view of mahendra.com.zone Configuration file */ $TTL 86400 @ IN SOA localhost. root.localhost ( 5 ; serial 28800 ; refresh 7200 ; retry 604800 ; expire 86400 ; ttl ) IN NS localhost. sky IN MX 1 192.168.5.1 sky IN A 192.168.5.1 mahendra.com IN CNAME admin.mahendra.com. host1 IN AAAA fe80::200:1cff:fe81:e1d0 redhat1 IN AAAA fe80::200:1cff:fe81:e1d0 penguin IN AAAA fe80::200:1cff:fe81:e1d0 node 2 IN A 192.168.5.4 node 1 IN A 192.168.5.3 Page 107

×