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

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + kingsabri kingsabri 4 months ago
    thanks .. plz put it allowed to downloading
Post a comment
Embed Video
Edit your comment Cancel

Favorites, Groups & Events

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

  1. Building a Linux IPv6 DNS Server /*Loading .sh (Shell Script) */ putChar() { i=1 while [ $i -le $3 ] do echo -n \"$1\" sleep $2 i=`expr $i + 1` done } clear echo putChar _ 0 80 echo -e \"\\n\" echo \" !!! Loading System Details\" echo -ne \"\\n\\t\\tit may take few seconds \" sleep 1 putChar '.' 0.25 20 putChar '.' 0 20 putChar _ 0 80 sleep 1 echo -ne \"\\n\\n\\n\\t--> Checking system details \" putChar '.' 0.5 8 echo -e \"\\n\\n\\t\\t-- Machine (hardware) type : `uname -m`\" Page 54
  2. Building a Linux IPv6 DNS Server sleep 2 echo -e \"\\t\\t-- Machine's network hostname : `uname -n`\" sleep 1 echo -e \"\\t\\t-- Operating system release : `uname -r`\" sleep 0.5 echo -e \"\\t\\t-- Operating system name : `uname -s`\" sleep 0.5 echo -e \"\\t\\t-- Host processor type : `uname -p`\" sleep 0.25 echo -e \"\\t\\t-- Operating system version : `uname -v`\" sleep 1 echo -ne \"\\n\\n\\t--> Checking for root user privilege \" putChar '.' 0.5 6 sleep 1 if [ \"`whoami`\" != \"root\" ] then echo -e \"\\n\\n\\t\\t-- Sorry this software has to be run by root user....\\n\\n\" sleep 2 echo -e \"\\n\\t\\tAborting.......\"; sleep 5 exit else sh run.sh echo -e \"\\n\\n\\t\\t-- found root user privileges !\" sleep 1 echo -ne \"\\n\\n\\t\\t\\t\\t\\t\\t\\t\\t \" putChar '->' 0.25 5 Page 55
  3. Building a Linux IPv6 DNS Server sleep 1 echo -e \"\\n\" 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(\"%c\", c); printf(\"\\n\"); } // end printChar void bu() { system(\"sh built.sh\"); } void Builder() { char ans, dirName[260]; char dir,command[260]; FILE *fp = fopen(\"SourceDir\", \"r\"); fscanf(fp, \"%s\", dirName); Page 56
  4. Building a Linux IPv6 DNS Server fclose(fp); printf(\"Enter the Dir. Name Default is '%s' is it o.k (y/n): \", dirName); scanf(\" %c\", &dir); if(dir == 'y') { printf(\"Ensure that U have copied the source files..\"); printf(\"Shall I Proceed...(y/n): \"); scanf(\" %c\", &ans); if(ans == 'y') { chdir(dirName); // system(\"cp -rf /usr/src/linux-2.4.21-4.EL/arch/i386/defconfig /usr/src/linux- 2.4.21-4.EL/arch/i386/defconfig.org\"); printChar('/',79); printChar('/',79); printf(\"\\n\"); printf(\"Press Any key to proceed with cleaning...\"); getchar(); getchar(); printChar('/',79); printChar('/',79); system(\"sleep 40\"); printf(\"\\n\"); printf(\"Press Any key to proceed with kernel image creation...\"); getchar(); /* system(\"make bzImage &> /dev/zero\");*/ bu(); system(\"sleep 60\"); printChar('*', 79); printChar('*', 79); Page 57
  5. Building a Linux IPv6 DNS Server printChar('*', 79); //strcpy(command,\"cp /Project/ntfssupportedkernel arch/i386/boot/bzImage\"); //system(command); printf(\"\\nProcess Completed Successfully!!!\\n\\n\"); } } else { printf(\"Enter the directory Name: \"); scanf(\"%s\", dirName); printf(\"Ensure that U have copied the source files..\"); printf(\"Shall I Proceed...(y/n): \"); scanf(\" %c\", &ans); printf(\"ans is %c\\n\", ans); if(ans == 'y') { chdir(dirName); system(\"make dep &> /dev/zero\"); // system(\"make dep | tee .o; ./.s\"); printChar('/',79); printChar('/',79); printf(\"\\n\"); printf(\"Press Any key to proceed with cleaning...\"); getchar(); getchar(); system(\"sleep 60\"); printChar('/',79); printChar('/',79); printf(\"\\n\"); printf(\"Press Any key to proceed with kernel image creation...\"); getchar(); Page 58
  6. Building a Linux IPv6 DNS Server printChar('/',79); printChar('/',79); printf(\"\\n\"); //system(\"sleep 60\"); printChar('*', 79); system(command); printChar('*', 79); printf(\"Process Completed Successfully!!!\\n\\n\"); } } } // 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, \"Cann't open Directory: %s\\n\", dirName); return; Page 59
  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(\".\", entry->d_name) == 0 || strcmp(\"..\", entry->d_name)==0) continue; printf(\"%s/\\n\", entry->d_name); } // end if } // end while } // end PrintDir void DirHandler() { FILE *fp = fopen(\"SourceDir\", \"w\"); char dirName[81]; char command[200]; char cmd[250]; char srcName[260], destName[260]; char pro; char defDir[] = \"/usr/src/\"; char srcRel[50], destRel[50]; printf(\"Enter the Dir To be scanned: \"); scanf(\"%s\", dirName); PrintDir(dirName, 0); printf(\"\\n\\n... That's all folks...\\n\"); printf(\"The default dir is '%s' Shall I proceed? (y/n): \", defDir); scanf(\" %c\", &pro); if(pro == 'n') { Page 60
  8. Building a Linux IPv6 DNS Server printf(\"Enter the Directory U want to be backed up: \"); scanf(\"%s\", srcName); printf(\"Now Enter the Directory name U want the sources to be in: \"); scanf(\"%s\", destName); command[0]='\\0'; strcat(command, \"cp -r \"); strcat(command, srcName); strcat(command, \" \"); strcat(command, destName); cmd[0] = '\\0'; strcat(cmd, command); printf(\"\\n Command %s\",cmd); printf(\"\\nPress any key to go ahead with backup....\"); printf(\"This process may take several minutes... pls. wait....\"); /* getchar(); getchar(); printf(\"\\n Command %s \", command);*/ getchar(); system(command); printf(\"\\nProcess Completed Successfully!!!\\n\\n\"); } else { printf(\"Enter the Directory U want to be backed up: \"); scanf(\"%s\", srcRel); srcName[0]='\\0'; strcpy(srcName, defDir); strcat(srcName, srcRel); printf(\"Now Enter the Directory name U want the sources to be in: \"); scanf(\"%s\", destRel); Page 61
  9. Building a Linux IPv6 DNS Server strcpy(destName, defDir); strcat(destName, destRel); command[0]='\\0'; strcat(command, \"cp -r \"); strcat(command, srcName); strcat(command, \" \"); strcat(command, destName); printf(\"\\nPress any key to go ahead with backup....\"); printf(\"This process may take several minutes... pls. wait....\"); getchar(); getchar(); system(command); printf(\"\\nProcess Completed Successfully!!!\\n\\n\"); } fprintf(fp, \"%s\", 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. 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 = \"\"; Thread memberAdder; public MemberAdderGUI(String title) { super(title); membersList = new Vector(); frame = this; c = getContentPane(); strBtnCaption = \"Start\"; pnlPortInfo = new JPanel(); pnlPortInfo.setLayout(new BorderLayout()); pnlPortInfo.add(\"West\", new JLabel(\"Port: \")); Page 63
  11. Building a Linux IPv6 DNS Server pnlPortInfo.add(\"Center\", jtfPort = new JTextField(7)); pnlPortInfo.add(\"East\", btnAction = new JButton(strBtnCaption)); btnAction.addActionListener(new Axn()); c.add(\"North\", pnlPortInfo); c.add(\"Center\", lstMembers = new java.awt.List(7)); c.add(\"South\", 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(\"Member Adder started and waiting...at '\" + port + \"'..!!\"); Socket clientSocket = null; while(true) Page 64
  12. Building a Linux IPv6 DNS Server { clientSocket = serverSocket.accept(); System.out.println(\"Connected to machine: \" + 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(\"Added '\" + ipAddress + \"' Successfully!!\"); } else { System.out.println(\"\\\"\" + ipAddress + \"\\\" has been added already!!!\"); tfStatus.setText(\"\\\"\" + ipAddress + \"\\\" has been added already!!!\"); } } Page 65
  13. Building a Linux IPv6 DNS Server public void printMembers() { System.out.println(\"\\n\\nList of Available members is..\\n\"); Enumeration list = membersList.elements(); while(list.hasMoreElements()) { System.out.println((String)list.nextElement()); } System.out.println(\"-----------------------that's all-----------------------\"); } class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCommand = ae.getActionCommand(); try { if(strCommand.equals(\"Start\")) { strBtnCaption = \"Stop\"; btnAction.setText(strBtnCaption); if(jtfPort.getText().equals(\"\")) { port = DEFAULT_PORT; } else Page 66
  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(\"Stop\")) { strBtnCaption = \"Start\"; btnAction.setText(strBtnCaption); serverSocket.close(); serverSocket = null; System.gc(); } } catch(Exception e) { System.out.println(\"MemberAdderGUI: Axn: \" + e); } // end try-catch Page 67
  15. Building a Linux IPv6 DNS Server } // end action } // end Axn public static void main(String [] args) { new MemberAdderGUI(\"Member List\"); } } // 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. 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(\"Host: \")); pnl2.add(new JLabel(\"Port: \")); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnRegister = new JButton(\"Register\")); btnRegister.addActionListener(new Axn()); pnlActions.add(btnClose = new JButton(\"Close\")); btnClose.addActionListener(new Axn()); pnlHostInfo.add(\"Center\", pnl1); pnlHostInfo.add(\"West\", pnl2); pnlHostInfo.add(\"South\", pnlActions); c.add(\"Center\", pnlHostInfo); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(200, 110); setLocation(80, 80); setVisible(true); } // end cons Page 69
  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(\"AddMe: Axn: \" + e); } } // end run } // end AddMe public class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCmd = ae.getActionCommand(); if(strCmd.equals(\"Register\")) { host = jtfHost.getText(); port = Integer.parseInt(jtfPort.getText()); new Thread(new AddMe()).start(); } else if(strCmd.equals(\"Close\")) { Page 70
  18. Building a Linux IPv6 DNS Server frame.dispose(); } } } // end Axn public static void main(String [] args) { new AddMeAsMemberGUI(\"Add Me As MEMBER\"); } } // 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. 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(\"Port: \")); pnlPortInfo.add(jtfPort = new JTextField(4)); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(2, 1)); pnlActions.add(btnStart = new JButton(\"Start\")); pnlActions.add(btnStop = new JButton(\"Stop\")); btnStart.addActionListener(new Axn()); btnStop.addActionListener(new Axn()); c.add(\"North\", pnlPortInfo); c.add(\"Center\", 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. Building a Linux IPv6 DNS Server { int port; stopServer = false; String strPort = jtfPort.getText(); if(!strPort.equals(\"\")) { port = Integer.parseInt(strPort); } else { port = 1234; } If (serverSok == null) { serverSok = new ServerSocket(port); } else { ; // do NOTHING } while(stopServer == false) { System.out.println(\"Waiting....at '\" + port + \"'\"); Socket clientSok = serverSok.accept(); System.out.println(\"Connected to: \" + clientSok); PrintWriter toClient = new PrintWriter(clientSok.getOutputStream(), true); toClient.println(\"Active\"); Page 73
  21. Building a Linux IPv6 DNS Server toClient.flush(); clientSok.close(); } // end while } catch(Exception e) { System.out.println(\"LookupServer: \" + e); } } // end run } public class Axn implements ActionListener { public void actionPerformed(ActionEvent ae) { String strCmd = ae.getActionCommand(); try { if(strCmd.equals(\"Start\")) { if(lookupSvr == null) { lookupSvr = new Thread(new LookupServer()); lookupSvr.start(); } else { System.out.println(\"Already Running!!!!\"); Page 74
  22. Building a Linux IPv6 DNS Server } } else if(strCmd.equals(\"Stop\")) { stopServer = true; serverSok.close(); serverSok = null; lookupSvr = null; System.gc(); System.out.println(\"Stopped!!\"); } // end if } catch(Exception e) { System.out.println(e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new LookUpServerGUI(\"Lookup Server\"); } } // end LookUpServerGUI /* LookUpClientGUI */ Page 75
  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(\"Host: \")); pnl1.add(jtfHost = new JTextField(15)); Page 76
  24. Building a Linux IPv6 DNS Server pnl1.add(new JLabel(\"Port: \")); pnl1.add(jtfPort = new JTextField(15)); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnLookup = new JButton(\"Lookup\")); btnLookup.addActionListener(new Axn()); pnlActions.add(btnClose = new JButton(\"Close\")); btnClose.addActionListener(new Axn()); pnlHostInfo.add(\"Center\", pnl1); pnlHostInfo.add(\"South\", pnlActions); c.add(\"Center\", pnlHostInfo); c.add(\"South\", 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(\"Lookup\")) { host = jtfHost.getText(); port = Integer.parseInt(jtfPort.getText()); Page 77
  25. Building a Linux IPv6 DNS Server new Thread(new LookupClient()).start(); } else if(strCmd.equals(\"Close\")) { 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(\"Active\")) { System.out.println(\"The Server is active...\"); tfStatus.setText(\"The Server is ACTIVE...\"); } } catch(Exception e) { System.out.println(\"Exception has come the server seems to be NOT ACTIVE..\"); tfStatus.setText(\"server seems to be NOT ACTIVE..\"); } // end try-catch Page 78
  26. Building a Linux IPv6 DNS Server } // end run } // end LookupClient public static void main(String [] args) { new LookUpClientGUI(\"Lookup Client\"); } } // 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. Building a Linux IPv6 DNS Server c = getContentPane(); jdp = new JDesktopPane(); c.add(jdp); mbar = new JMenuBar(); mnuDNS = new JMenu(\"DNS\"); jmi = new JMenuItem(\"Control Panel\", 'C'); jmi.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); mnuDNS.addSeparator(); jmi = new JMenuItem(\"IPv6 Address\", 'I'); jmi.setAccelerator(KeyStroke.getKeyStroke('I', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); jmi = new JMenuItem(\"IPv4 Address\", 'A'); jmi.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); mnuDNS.addSeparator(); jmi = new JMenuItem(\"Exit\", 'X'); jmi.setAccelerator(KeyStroke.getKeyStroke('X', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuDNS.add(jmi); mnuHelp = new JMenu(\"Help\"); Page 80
  28. Building a Linux IPv6 DNS Server jmi = new JMenuItem(\"Contents\", 'C'); jmi.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuHelp.add(jmi); jmi = new JMenuItem(\"Search...\", 'S'); jmi.setAccelerator(KeyStroke.getKeyStroke('S', java.awt.event.InputEvent.ALT_MASK)); jmi.addActionListener(new Axn()); mnuHelp.add(jmi); mnuHelp.addSeparator(); jmi = new JMenuItem(\"About\", '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. Building a Linux IPv6 DNS Server public void actionPerformed(ActionEvent ae) { String cmdString = ae.getActionCommand(); if(cmdString.equals(\"Exit\")) { int result = JOptionPane.showConfirmDialog(frame, \"Do you Really want to quit?\", \"Quitting?\", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if(result == JOptionPane.YES_OPTION) frame.dispose(); } else if(cmdString.equals(\"Control Panel\")) { JInternalFrame jif = new DNSpanelIF(\"DNS panel\"); jdp.add(jif); } else if(cmdString.equals(\"IPv6 Address\")) { JInternalFrame jif = new Ipv6RecordAdderIF(\"IPv6 DNS Records\"); jdp.add(jif); } else if(cmdString.equals(\"IPv4 Address\")) { JInternalFrame jif = new Ipv4RecordAdderIF(\"IPv4 DNS Records\"); jdp.add(jif); } } // end action Page 82
  30. Building a Linux IPv6 DNS Server } // end Axn class WinLstner extends WindowAdapter { public void windowClosing(WindowEvent we) { int result = JOptionPane.showConfirmDialog(frame, \"Do you Really want to quit?\", \"Quitting?\", 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(\"IPv6 ready DNS\"); } // end main } // end DNSmain /* DNShandler */ import java.io.*; public class DNShandler { public void startDNS() { Page 83
  31. Building a Linux IPv6 DNS Server try { Runtime r = Runtime.getRuntime(); Process p = r.exec(\"service named start\"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = \"\"; while((line = br.readLine()) != null) System.out.println(line); } catch(Exception e) { System.out.println(\"startDNS:: \" + e); } } public void stopDNS() { try { Runtime r = Runtime.getRuntime(); Process p = r.exec(\"service named stop\"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = \"\"; while((line = br.readLine()) != null) System.out.println(line); } Page 84
  32. Building a Linux IPv6 DNS Server catch(Exception e) { System.out.println(\"stopDNS:: \" + e); } } public void reloadDNS() { try { Runtime r = Runtime.getRuntime(); Process p = r.exec(\"service named reload\"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = \"\"; while((line = br.readLine()) != null) System.out.println(line); } catch(Exception e) { System.out.println(\"reloadDNS:: \" + e); } } public static void main(String [] args) { new DNShandler().reloadDNS(); Page 85
  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(\"Start\")); pnlActions.add(btnStop = new JButton(\"Stop\")); pnlActions.add(btnRestart = new JButton(\"Restart\")); pnlActions.add(btnClose = new JButton(\"Close\")); btnStart.addActionListener(new Axn()); btnStop.addActionListener(new Axn()); Page 86
  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(\"Start\")) { new DNShandler().startDNS(); } else if(strCommand.equals(\"Stop\")) { new DNShandler().stopDNS(); } else if(strCommand.equals(\"Restart\")) { new DNShandler().reloadDNS(); } else if(strCommand.equals(\"Close\")) { frame.dispose(); Page 87
  35. Building a Linux IPv6 DNS Server } } // end action } // end Axn public static void main(String [] args) { new DNSpanel(\"DNS panel\"); } // 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. Building a Linux IPv6 DNS Server pnlActions.setLayout(new GridLayout(2, 2)); pnlActions.add(btnStart = new JButton(\"Start\")); pnlActions.add(btnStop = new JButton(\"Stop\")); pnlActions.add(btnRestart = new JButton(\"Restart\")); pnlActions.add(btnClose = new JButton(\"Close\")); 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(\"Start\")) { new DNShandler().startDNS(); } Page 89
  37. Building a Linux IPv6 DNS Server else if(strCommand.equals(\"Stop\")) { new DNShandler().stopDNS(); } else if(strCommand.equals(\"Restart\")) { new DNShandler().reloadDNS(); } else if(strCommand.equals(\"Close\")) { frame.dispose(); } } // end action } // end Axn public static void main(String [] args) { new DNSpanelIF(\"DNS panel\"); } // end main } // end DNSpanelIF /* Ipv4RecordAdder */ import java.io.*; import java.net.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; Page 90
  38. Building a Linux IPv6 DNS Server public class Ipv4RecordAdder extends JFrame { String zoneFileName; String dnsDirectory = \"/var/named/\"; // 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(\"Domain Name : \")); pnlCenter.add(jtfDomainName = new JTextField()); pnlCenter.add(new JLabel(\"Host Name : \")); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(\"IPv4 Address: \")); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnAdd = new JButton(\"Add\")); pnlActions.add(btnClose = new JButton(\"Close\")); btnAdd.addActionListener(new Axn()); Page 91
  39. Building a Linux IPv6 DNS Server btnClose.addActionListener(new Axn()); c.add(\"Center\", pnlCenter); c.add(\"South\", 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(\"Add\")) { String domainName = jtfDomainName.getText(); String zoneFileName = dnsDirectory + domainName + \".zone\"; String hostName = jtfHostName.getText(); String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + \"\\tIN\\tA\\t\" + ipAddress); System.out.println(\"Record Added Successfully!!!!\"); // Clear the TextFields Page 92
  40. Building a Linux IPv6 DNS Server jtfDomainName.setText(\"\"); jtfHostName.setText(\"\"); jtfAddress.setText(\"\"); zoneFile.close(); } else if(cmdString.equals(\"Close\")) { frame.dispose(); } } catch(Exception e) { System.out.println(\"Ipv4 Add: \" + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new Ipv4RecordAdder(\"IPv4 Record Adder..\"); } // end main } // end Ipv4RecordAdder /* Ipv4RecordAdderIF (Internal Frame) */ import java.io.*; import java.net.*; import java.awt.*; Page 93
  41. Building a Linux IPv6 DNS Server import javax.swing.*; import java.awt.event.*; public class Ipv4RecordAdderIF extends JInternalFrame { String zoneFileName; String dnsDirectory = \"/var/named/\"; // 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(\"Domain Name : \")); pnlCenter.add(jtfDomainName = new JTextField()); pnlCenter.add(new JLabel(\"Host Name : \")); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(\"IPv4 Address: \")); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); Page 94
  42. Building a Linux IPv6 DNS Server pnlActions.add(btnAdd = new JButton(\"Add\")); pnlActions.add(btnClose = new JButton(\"Close\")); btnAdd.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(\"Center\", pnlCenter); c.add(\"South\", 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(\"Add\")) { String domainName = jtfDomainName.getText(); String zoneFileName = dnsDirectory + domainName + \".zone\"; String hostName = jtfHostName.getText(); Page 95
  43. Building a Linux IPv6 DNS Server String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + \"\\tIN\\tA\\t\" + ipAddress); System.out.println(\"Record Added Successfully!!!!\"); // Clear the TextFields jtfDomainName.setText(\"\"); jtfHostName.setText(\"\"); jtfAddress.setText(\"\"); zoneFile.close(); } else if(cmdString.equals(\"Close\")) { frame.dispose(); } } catch(Exception e) { System.out.println(\"Ipv4 Add: \" + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new Ipv4RecordAdderIF(\"IPv4 Record Adder..\"); } // end main } // end Ipv4RecordAdderIF Page 96
  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 = \"/var/named/\"; // 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(\"Domain Name : \")); pnlCenter.add(jtfDomainName = new JTextField()); Page 97
  45. Building a Linux IPv6 DNS Server pnlCenter.add(new JLabel(\"Host Name : \")); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(\"IPv6 Address: \")); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnAdd = new JButton(\"Add\")); pnlActions.add(btnClose = new JButton(\"Close\")); btnAdd.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(\"Center\", pnlCenter); c.add(\"South\", 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(\"Add\")) { String domainName = jtfDomainName.getText(); Page 98
  46. Building a Linux IPv6 DNS Server String zoneFileName = dnsDirectory + domainName + \".zone\"; String hostName = jtfHostName.getText(); String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + \"\\t\\tIN\\tAAAA\\t\" + ipAddress); System.out.println(\"Record Added Successfully!!!!\"); // Clear the TextFields jtfDomainName.setText(\"\"); jtfHostName.setText(\"\"); jtfAddress.setText(\"\"); zoneFile.close(); } else if(cmdString.equals(\"Close\")) { frame.dispose(); } } catch(Exception e) { System.out.println(\"Ipv6 Add: \" + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { Page 99
  47. Building a Linux IPv6 DNS Server new Ipv6RecordAdder(\"IPv6 Record Adder..\"); } // 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 = \"/var/named/\"; // 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. Building a Linux IPv6 DNS Server pnlCenter.add(new JLabel(\"Domain Name : \")); pnlCenter.add(jtfDomainName = new JTextField()); pnlCenter.add(new JLabel(\"Host Name : \")); pnlCenter.add(jtfHostName = new JTextField()); pnlCenter.add(new JLabel(\"IPv6 Address: \")); pnlCenter.add(jtfAddress = new JTextField()); pnlActions = new JPanel(); pnlActions.setLayout(new GridLayout(1, 2)); pnlActions.add(btnAdd = new JButton(\"Add\")); pnlActions.add(btnClose = new JButton(\"Close\")); btnAdd.addActionListener(new Axn()); btnClose.addActionListener(new Axn()); c.add(\"Center\", pnlCenter); c.add(\"South\", 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. Building a Linux IPv6 DNS Server { String cmdString = ae.getActionCommand(); try { if(cmdString.equals(\"Add\")) { String domainName = jtfDomainName.getText(); String zoneFileName = dnsDirectory + domainName + \".zone\"; String hostName = jtfHostName.getText(); String ipAddress = jtfAddress.getText(); PrintWriter zoneFile = new PrintWriter(new FileOutputStream(zoneFileName, true)); zoneFile.println(hostName + \"\\t\\tIN\\tAAAA\\t\" + ipAddress); System.out.println(\"Record Added Successfully!!!!\"); // Clear the TextFields jtfDomainName.setText(\"\"); jtfHostName.setText(\"\"); jtfAddress.setText(\"\"); zoneFile.close(); } else if(cmdString.equals(\"Close\")) { frame.dispose(); } } catch(Exception e) Page 102
  50. Building a Linux IPv6 DNS Server { System.out.println(\"Ipv6 Add: \" + e); } // end try-catch } // end action } // end Axn public static void main(String [] args) { new Ipv6RecordAdderIF(\"IPv6 Record Adder..\"); } // 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(\"Server Ready!!!\"); Socket client = sok.accept(); Page 103
  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(\"Client has sent...\" + 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. Building a Linux IPv6 DNS Server Socket sok = new Socket(host, port); System.out.print(\"Enter some text: \"); 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. 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 \"/etc/named.custom\"; include \"/etc/rndc.key\"; #options { # listen-on-v6 { any; }; #}; zone \"localhost\" { type master; file \"localhost.zone\"; }; zone \"mahendra.com\" { type master; file \"mahendra.com.zone\"; }; Page 106
  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

+ Hari Hari , 2 years ago

custom

782 views, 0 favs, 0 embeds more stats

Source Code of Building Linux IPv6 DNS Server (Comp more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 782
    • 782 on SlideShare
    • 0 from embeds
  • Comments 1
  • Favorites 0
  • Downloads 0
Most viewed embeds

more

All embeds

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories